mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
ptx: fix panic when reference length exceeds line width (#9816)
Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
This commit is contained in:
co-authored by
Sylvestre Ledru
parent
27fd41125b
commit
1f8da8d400
@@ -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 {
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user