Repository navigation
[IMPROVEMENT] Remove dead seek guards in buffered_read_opt() - #2326
Conversation
… cannot buffered_read_opt()'s seek branch guarded against moving before the start of the file with "op + bytes < 0". That could not fire: bytes is unsigned, so the sum was evaluated unsigned and never went negative, and every caller passes a forward distance anyway. What can fail is LSEEK itself. On error it returns -1, and the code then computed "np - op" from two error values and reported the result as a byte count. Today that lands on 0 and the loop exits, so the observable behaviour is unchanged -- but only by arithmetic accident, and the next reader has no way to tell that the guard above it was inert. Check what actually fails, and return the bytes copied so far rather than inventing a distance from two failures. Noted while reviewing the MSVC narrowing warnings for #2325, which flagged this line as dead rather than wrong and left it out of that change deliberately.
Both skip paths had "if (op + bytes < 0) return 0;". bytes is a size_t, so the sum is unsigned and the check can never be true. Removing it changes no behaviour; failed seeks are already handled below each guard. Replaces the earlier early-return approach, which changed how the buffered path handles a pipe that can't seek.
CCExtractor CI platform finished running the test files on linux. 172/238 tests matched the approved output:
66 tests do not match the approved output. That is the pass/fail verdict. Whether this branch caused it is a separate question, answered below.
Compared with the tip of master — test 9984, commit 24d1e0a:
Compared with the commit this branch was cut from: the same run as the tip of master (test 9984), so the comparison above already covers it. No test changes behaviour relative to the tip of master: every failure above fails there too, byte for byte. The approved output for those tests is out of date, which is a baseline to review rather than a regression in this branch. |
CCExtractor CI platform finished running the test files on windows. 172/238 tests matched the approved output:
66 tests do not match the approved output. That is the pass/fail verdict. Whether this branch caused it is a separate question, answered below.
Compared with the tip of master — test 9985, commit 24d1e0a:
Compared with the commit this branch was cut from: the same run as the tip of master (test 9985), so the comparison above already covers it. No test changes behaviour relative to the tip of master: every failure above fails there too, byte for byte. The approved output for those tests is out of date, which is a baseline to review rather than a regression in this branch. |
Both skip paths in
buffered_read_opt()had:bytesis asize_t, soop + bytesis unsigned and can never be negative. The guard is dead code, and this removes it in both places. No behaviour changes: a failedLSEEKis already handled below each guard (thei == 0path in the buffered branch, and theop == -1 && np == -1pipe fallback in the unbuffered one).Testing, current master vs this branch: 10 samples, each with and without
--bufferinput, plus a 608 TS piped through--stdin. All byte-identical, same exit codes.