1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 11:07:44 +00:00

Merge pull request #5543 from pawelngei/printf-x-incorrect-exit-code-when-invalid-value

printf: Fixing incorrect exit code when passing invalid value to %x
This commit is contained in:
Terts Diepraam 2023-11-15 21:20:58 +01:00 committed by GitHub
commit da84583b5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View file

@ -8,10 +8,11 @@
//! formatter for unsigned and signed int subs //! formatter for unsigned and signed int subs
//! unsigned int: %X %x (hex u64) %o (octal u64) %u (base ten u64) //! unsigned int: %X %x (hex u64) %o (octal u64) %u (base ten u64)
//! signed int: %i %d (both base ten i64) //! signed int: %i %d (both base ten i64)
use crate::error::set_exit_code;
use crate::features::tokenize::num_format::num_format::warn_expected_numeric;
use super::super::format_field::FormatField; use super::super::format_field::FormatField;
use super::super::formatter::{ use super::super::formatter::{get_it_at, Base, FormatPrimitive, Formatter, InitialPrefix};
get_it_at, warn_incomplete_conv, Base, FormatPrimitive, Formatter, InitialPrefix,
};
use std::i64; use std::i64;
use std::u64; use std::u64;
@ -112,7 +113,8 @@ impl Intf {
} }
} }
_ => { _ => {
warn_incomplete_conv(str_in); warn_expected_numeric(str_in);
set_exit_code(1);
break; break;
} }
} }

View file

@ -258,6 +258,14 @@ fn sub_num_hex_upper() {
.stdout_only("thirty in hex is 1E"); .stdout_only("thirty in hex is 1E");
} }
#[test]
fn sub_num_hex_non_numerical() {
new_ucmd!()
.args(&["parameters need to be numbers %X", "%194"])
.fails()
.code_is(1);
}
#[test] #[test]
fn sub_num_float() { fn sub_num_float() {
new_ucmd!() new_ucmd!()