Skip to content

ptx: fix panic when reference length exceeds line width#9816

Merged
sylvestre merged 2 commits intouutils:mainfrom
CrazyRoka:ptx-fix-overflow
Jan 9, 2026
Merged

ptx: fix panic when reference length exceeds line width#9816
sylvestre merged 2 commits intouutils:mainfrom
CrazyRoka:ptx-fix-overflow

Conversation

@CrazyRoka
Copy link
Contributor

@CrazyRoka CrazyRoka commented Dec 24, 2025

Description:

Fixes a panic in ptx where subtraction overflow occurred if the generated reference string (filename + line number) was longer than the specified line width (e.g., ptx -w 1 -A long_file).

thread 'main' (213854) panicked at src/uu/ptx/src/ptx.rs:750:9:
attempt to subtract with overflow

Fix:

Changed direct subtraction config.line_width -= max_ref_len to saturating_sub. If the reference consumes the entire line, the available width for context simply becomes 0.

Tests:

Fixes failure in GNU test tests/ptx/ptx-overrun.sh.
Added new regression test test_narrow_width_with_long_reference_no_panic.

@sylvestre sylvestre merged commit 1f8da8d into uutils:main Jan 9, 2026
128 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

Comments