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

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
This commit is contained in:
Rostyslav Toch
2026-01-09 21:04:02 +01:00
committed by GitHub
co-authored by Sylvestre Ledru
parent 27fd41125b
commit 1f8da8d400
2 changed files with 12 additions and 1 deletions
+3 -1
View File
@@ -788,7 +788,9 @@ fn write_traditional_output(
} else {
0
};
config.line_width -= max_ref_len;
// Use saturating_sub to prevent panic if the reference is wider than the line width.
config.line_width = config.line_width.saturating_sub(max_ref_len);
}
for word_ref in words {
+9
View File
@@ -338,3 +338,12 @@ fn test_unicode_truncation_alignment() {
.succeeds()
.stdout_only(" / bar\n föö/\n");
}
#[test]
fn test_narrow_width_with_long_reference_no_panic() {
new_ucmd!()
.args(&["-w", "1", "-A"])
.pipe_in("content")
.succeeds()
.stdout_only(":1 content\n");
}