From 69d81a1c1b2e4881b751ee24f8eb70c0dfaa05d9 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 7 Mar 2012 11:57:47 +0100 Subject: printf: fix this case: printf "%b" '\0057usr\0057bin\n' It was not accepting \0NNN. Standard printf tool does. function old new delta printf_main 869 886 +17 Signed-off-by: Denys Vlasenko --- coreutils/printf.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'coreutils/printf.c') diff --git a/coreutils/printf.c b/coreutils/printf.c index 1437951a8..3dd43a978 100644 --- a/coreutils/printf.c +++ b/coreutils/printf.c @@ -131,13 +131,28 @@ static double my_xstrtod(const char *arg) return result; } +/* Handles %b */ static void print_esc_string(const char *str) { char c; while ((c = *str) != '\0') { str++; - if (c == '\\') - c = bb_process_escape_sequence(&str); + if (c == '\\') { + /* %b also accepts 4-digit octals of the form \0### */ + if (*str == '0') { + if ((unsigned char)(str[1] - '0') < 8) { + /* 2nd char is 0..7: skip leading '0' */ + str++; + } + } + { + /* optimization: don't force arg to be on-stack, + * use another variable for that. */ + const char *z = str; + c = bb_process_escape_sequence(&z); + str = z; + } + } putchar(c); } } -- cgit v1.2.3