diff --git a/src/builtins/printf.rs b/src/builtins/printf.rs index 01631ab0c..d3be1f710 100644 --- a/src/builtins/printf.rs +++ b/src/builtins/printf.rs @@ -239,6 +239,13 @@ fn verify_numeric(&mut self, s: &wstr, end: &wstr, errcode: Option) { } } + fn handle_sprintf_error(&mut self, err: fish_printf::Error) { + match err { + fish_printf::Error::Overflow => self.fatal_error(wgettext!("Number out of range")), + _ => panic!("unhandled error: {err:?}"), + } + } + /// Evaluate a printf conversion specification. SPEC is the start of the directive, and CONVERSION /// specifies the type of conversion. SPEC does not include any length modifier or the /// conversion specifier itself. FIELD_WIDTH and PRECISION are the field width and @@ -268,7 +275,7 @@ macro_rules! append_output_fmt { $fmt, &self.locale, &mut [$($arg.to_arg()),*] - ).expect("sprintf failed"); + ).err().map(|err| self.handle_sprintf_error(err)); } } } diff --git a/tests/checks/printf.fish b/tests/checks/printf.fish index f1cc238e1..c905a4ebe 100644 --- a/tests/checks/printf.fish +++ b/tests/checks/printf.fish @@ -151,3 +151,6 @@ echo # This is how mc likes to encode the directory we should cd to. printf '%b\n' '\0057foo\0057bar\0057' # CHECK: /foo/bar/ + +printf %18446744073709551616s +# CHECKERR: Number out of range