Skip to content

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.

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.

1 participant