Skip to content

[IMPROVEMENT] Remove dead seek guards in buffered_read_opt() - #2326

Merged
cfsmp3 merged 3 commits into
masterfrom
fix/buffered-read-opt-dead-seek-guard
Nov 11, 2026
Merged

cfsmp3 merged 3 commits into
masterfrom
fix/buffered-read-opt-dead-seek-guard

Conversation

@cfsmp3

@cfsmp3 cfsmp3 commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Both skip paths in buffered_read_opt() had:

if (op + bytes < 0) // Would mean moving beyond start of file: Not supported
	return 0;

bytes is a size_t, so op + bytes is unsigned and can never be negative. The guard is dead code, and this removes it in both places. No behaviour changes: a failed LSEEK is already handled below each guard (the i == 0 path in the buffered branch, and the op == -1 && np == -1 pipe 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.

cfsmp3 added 3 commits August 17, 2026 00:06
… 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.
@cfsmp3 cfsmp3 changed the title [FIX] file_functions: check the seek that can fail instead of one that cannot [IMPROVEMENT] Remove dead seek guards in buffered_read_opt() Nov 10, 2026
@ccextractor-bot

Copy link
Copy Markdown
Collaborator
CCExtractor CI platform finished running the test files on linux. 172/238 tests matched the approved output:
Report Name Tests Passed
Broken 9/13
CEA-708 2/14
DVB 0/7
DVD 3/3
DVR-MS 2/2
General 26/28
Hardsubx 1/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 69/86
Teletext 0/21
WTV 12/13
XDS 32/34

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:

  • 0 pass there and fail here
  • 0 fail there and pass here
  • 0 fail on both, with different output
  • 66 fail on both, byte for byte the same

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-bot

Copy link
Copy Markdown
Collaborator
CCExtractor CI platform finished running the test files on windows. 172/238 tests matched the approved output:
Report Name Tests Passed
Broken 9/13
CEA-708 2/14
DVB 0/7
DVD 3/3
DVR-MS 2/2
General 26/28
Hardsubx 1/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 69/86
Teletext 0/21
WTV 12/13
XDS 32/34

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:

  • 0 pass there and fail here
  • 0 fail there and pass here
  • 0 fail on both, with different output
  • 66 fail on both, byte for byte the same

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.

@cfsmp3
cfsmp3 merged commit 77daadd into master Nov 11, 2026
49 of 51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants