mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
fix(date): handle width overflow in format modifiers
Update `apply_modifiers` to return `Result<String, FormatError>` and check for integer overflow when calculating padding length. This prevents potential panics or incorrect formatting when very large width values are specified. The change adds proper error handling for the "field width too large" case and propagates errors through the formatting pipeline.
This commit is contained in:
@@ -2507,6 +2507,16 @@ fn test_date_format_modifier_edge_cases() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_date_format_modifier_huge_width_fails_without_abort() {
|
||||
let format = format!("+%{}c", usize::MAX);
|
||||
new_ucmd!()
|
||||
.arg(&format)
|
||||
.fails()
|
||||
.code_is(1)
|
||||
.stderr_contains("field width too large");
|
||||
}
|
||||
|
||||
// Tests for --debug flag
|
||||
#[test]
|
||||
fn test_date_debug_basic() {
|
||||
|
||||
Reference in New Issue
Block a user