1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

printf: error on missing hexadecial escape value

Change `printf` to correctly terminate with an error message when an
escape sequence starts with `\x` but doesn't include a literal
hexadecimal value after. For example, before this commit,

    printf '\x'

would output `\x`, but after this commit, it terminates with an error
message,

    printf: missing hexadecimal number in escape

Fixes #7097
This commit is contained in:
Jeffrey Finkelstein 2025-02-02 11:07:31 -05:00
parent c2505841e0
commit db280b6e9f
3 changed files with 44 additions and 22 deletions

View file

@ -46,6 +46,15 @@ fn escaped_hex() {
new_ucmd!().args(&["\\x41"]).succeeds().stdout_only("A");
}
#[test]
fn test_missing_escaped_hex_value() {
new_ucmd!()
.arg(r"\x")
.fails()
.code_is(1)
.stderr_only("printf: missing hexadecimal number in escape\n");
}
#[test]
fn escaped_octal() {
new_ucmd!().args(&["\\101"]).succeeds().stdout_only("A");