diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2012-03-07 11:57:47 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2012-03-07 11:57:47 +0100 |
commit | 69d81a1c1b2e4881b751ee24f8eb70c0dfaa05d9 (patch) | |
tree | b71b6fb3ba32baf73d862b19db991e4d3e5e1c59 | |
parent | d4acaf70c586ea72fce0e4af4cba87d4a6d00655 (diff) | |
download | busybox-w32-69d81a1c1b2e4881b751ee24f8eb70c0dfaa05d9.tar.gz busybox-w32-69d81a1c1b2e4881b751ee24f8eb70c0dfaa05d9.tar.bz2 busybox-w32-69d81a1c1b2e4881b751ee24f8eb70c0dfaa05d9.zip |
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 <vda.linux@googlemail.com>
-rw-r--r-- | coreutils/printf.c | 19 |
1 files changed, 17 insertions, 2 deletions
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) | |||
131 | return result; | 131 | return result; |
132 | } | 132 | } |
133 | 133 | ||
134 | /* Handles %b */ | ||
134 | static void print_esc_string(const char *str) | 135 | static void print_esc_string(const char *str) |
135 | { | 136 | { |
136 | char c; | 137 | char c; |
137 | while ((c = *str) != '\0') { | 138 | while ((c = *str) != '\0') { |
138 | str++; | 139 | str++; |
139 | if (c == '\\') | 140 | if (c == '\\') { |
140 | c = bb_process_escape_sequence(&str); | 141 | /* %b also accepts 4-digit octals of the form \0### */ |
142 | if (*str == '0') { | ||
143 | if ((unsigned char)(str[1] - '0') < 8) { | ||
144 | /* 2nd char is 0..7: skip leading '0' */ | ||
145 | str++; | ||
146 | } | ||
147 | } | ||
148 | { | ||
149 | /* optimization: don't force arg to be on-stack, | ||
150 | * use another variable for that. */ | ||
151 | const char *z = str; | ||
152 | c = bb_process_escape_sequence(&z); | ||
153 | str = z; | ||
154 | } | ||
155 | } | ||
141 | putchar(c); | 156 | putchar(c); |
142 | } | 157 | } |
143 | } | 158 | } |