aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2021-07-11 18:16:10 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2021-07-11 18:16:10 +0200
commitcaa93ecdd3a9b998a69dcbfafdddbc9c58887ec3 (patch)
treedca825b9488bd52398688ee52b41bc6473fff3e7
parentf5f336e787fd8367d24de5fe3b341ebffb74c2c2 (diff)
downloadbusybox-w32-caa93ecdd3a9b998a69dcbfafdddbc9c58887ec3.tar.gz
busybox-w32-caa93ecdd3a9b998a69dcbfafdddbc9c58887ec3.tar.bz2
busybox-w32-caa93ecdd3a9b998a69dcbfafdddbc9c58887ec3.zip
awk: fix corner case in awk_printf
Example where it wasn't working: awk 'BEGIN { printf "qwe %s rty %c uio\n", "a", 0, "c" }' - the NUL printing in %c caused premature stop of printing. function old new delta awk_printf 593 596 +3 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--editors/awk.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/editors/awk.c b/editors/awk.c
index 6c60a0615..465033f5f 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -2359,11 +2359,11 @@ static char *awk_printf(node *n, size_t *len)
2359 * printf "%99999s", "BOOM" 2359 * printf "%99999s", "BOOM"
2360 */ 2360 */
2361 if (c == 'c') { 2361 if (c == 'c') {
2362 c = is_numeric(arg) ? getvar_i(arg) : *getvar_s(arg); 2362 char cc = is_numeric(arg) ? getvar_i(arg) : *getvar_s(arg);
2363 s = xasprintf(s, c); 2363 s = xasprintf(s, cc);
2364 /* + 1 if c == NUL: handle printf "%c" 0 case 2364 /* + 1 if cc == NUL: handle printf "%c" 0 case
2365 * (and printf "%22c" 0 etc, but still fails for e.g. printf "%-22c" 0) */ 2365 * (and printf "%22c" 0 etc, but still fails for e.g. printf "%-22c" 0) */
2366 slen = strlen(s) + (c == '\0'); 2366 slen = strlen(s) + (cc == '\0');
2367 } else { 2367 } else {
2368 if (c == 's') { 2368 if (c == 's') {
2369 s = xasprintf(s, getvar_s(arg)); 2369 s = xasprintf(s, getvar_s(arg));