klibc-bot for Herbert Xu
2020-Mar-28 21:48 UTC
[klibc] [klibc:update-dash] dash: [BUILTIN] Optimise handling of backslash octals in printf
Commit-ID: 298ca1e50131be8fae13c629aca17507928271d3 Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=298ca1e50131be8fae13c629aca17507928271d3 Author: Herbert Xu <herbert at gondor.apana.org.au> AuthorDate: Mon, 27 Oct 2014 16:12:49 +0800 Committer: Ben Hutchings <ben at decadent.org.uk> CommitDate: Sat, 28 Mar 2020 21:42:54 +0000 [klibc] dash: [BUILTIN] Optimise handling of backslash octals in printf [ dash commit a68498993413cd15f9b852ca32afd368e1792b51 ] This patch removes the duplicate octal handling for %b by reusing the existing code in conv_escape. Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au> Signed-off-by: Ben Hutchings <ben at decadent.org.uk> --- usr/dash/bltin/printf.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/usr/dash/bltin/printf.c b/usr/dash/bltin/printf.c index 72f89883..0e150d36 100644 --- a/usr/dash/bltin/printf.c +++ b/usr/dash/bltin/printf.c @@ -276,8 +276,8 @@ conv_escape_str(char *str, char **sp) if (ch != '\\') continue; - ch = *str++; - if (ch == 'c') { + c = *str++; + if (c == 'c') { /* \c as in SYSV echo - abort all processing.... */ c = ch = 0x100; continue; @@ -288,24 +288,11 @@ conv_escape_str(char *str, char **sp) * They start with a \0, and are followed by 0, 1, 2, * or 3 octal digits. */ - if (ch == '0') { - unsigned char i; - i = 3; - c = 0; - do { - unsigned k = octtobin(*str); - if (k > 7) - break; - str++; - c <<= 3; - c += k; - } while (--i); - continue; - } + if (c == '0' && isodigit(*str)) + str++; /* Finally test for sequences valid in the format string */ str = conv_escape(str - 1, &c); - ch = c; } while (STPUTC(c, cp), (char)ch); *sp = cp; @@ -326,12 +313,11 @@ conv_escape(char *str, int *conv_ch) switch (ch) { default: - case 0: - value = '\\'; - goto out; + if (!isodigit(*str)) { + value = '\\'; + goto out; + } - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': ch = 3; value = 0; do {
Possibly Parallel Threads
- [klibc:update-dash] [BUILTIN] Optimise handling of backslash octals in printf
- [klibc:update-dash] [BUILTIN] Handle embedded NULs correctly in printf
- [klibc:update-dash] dash: [BUILTIN] Handle embedded NULs correctly in printf
- [git patch] klibc dash 0.5.4 update
- [klibc:update-dash] dash: Fix some cosmetic differences from upstream dash