When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
11 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
I recommend making a minimal reproducible example, so turning this code into as small of a program as possible that still showcases your bug
You have an off-by-one in your loop counting logic
It's also needlessly convoluted. The last_command boolean serves no purpose other than to reimplement an otherwise normal for loop into a strange hack
Just change the while loop to:
for (int i = 0; i < pipe_count; ++i) {
// ...
}
without any funny stuff at the end. Remove the last_command variable entirely, as well as lines 78-82.
There's another obvious bug on line 56. You access pipefd[WRITE+offset*2] although offset is already multiplied by 2 on line 16. You're going to access beyond the end of pipefd with this.
And your close() calls are buggy. You likely haven't spotted the problem yet because of readability issues in the way the code is written.
Correction: the lines 24 and 45 have buggy close() calls, the rest are ok
What i mean is
// Bug
close(pipefd[WRITE]+offset);
// OK
close(pipefd[WRITE+offset]);
That sort of mistake is difficult to spot even when looking directly at the incorrect line of code.
@dense pelican Has your question been resolved? If so, type !solved :)