aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/printf.c
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-08-17 19:53:56 -0700
committerRob Landley <rob@landley.net>2019-08-19 11:23:41 -0500
commit81518f643d4d53b035b2cefbce25f06bd3cb5079 (patch)
tree9420219c83f68c0345b770a31d7958dc1eb6295a /toys/posix/printf.c
parentaa88ba047fa4210c03c3ad1168f84261167c3644 (diff)
downloadtoybox-81518f643d4d53b035b2cefbce25f06bd3cb5079.tar.gz
echo/printf: expand test cases, fix \x corner cases.
The behavior with "\xAV" (where the second hex digit is invalid) is different from the behavior with "\xVA", and echo and printf differ from each other.
Diffstat (limited to 'toys/posix/printf.c')
-rw-r--r--toys/posix/printf.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/toys/posix/printf.c b/toys/posix/printf.c
index 5448d8c7..b51eddc0 100644
--- a/toys/posix/printf.c
+++ b/toys/posix/printf.c
@@ -9,12 +9,12 @@
USE_PRINTF(NEWTOY(printf, "<1?^", TOYFLAG_USR|TOYFLAG_BIN))
-config PRINTF
+config PRINTF
bool "printf"
default y
help
usage: printf FORMAT [ARGUMENT...]
-
+
Format and print ARGUMENT(s) according to FORMAT, using C printf syntax
(% escapes for cdeEfgGiosuxX, \ escapes for abefnrtv0 or \OCTAL or \xHEX).
*/
@@ -61,11 +61,8 @@ static int handle_slash(char **esc_val, int posix)
num = tolower(*ptr) - '0';
if (num >= 'a'-'0') num += '0'-'a'+10;
if (num >= base) {
- // Don't parse invalid hex value ala "\xvd", print it verbatim
- if (base == 16 && len == 2) {
- ptr--;
- result = '\\';
- }
+ // "\xav" is "\xa"+"v", but "\xva" is an error.
+ if (base == 16 && len == 2) error_exit("bad \\x");
break;
}
result = (result*base)+num;