diff options
author | Denys Vlasenko | 2021-07-12 11:27:11 +0200 |
---|---|---|
committer | Denys Vlasenko | 2021-07-12 11:27:11 +0200 |
commit | 8d269ef85984f6476e7fdbec2c5a70f3b5c48a72 (patch) | |
tree | 212f9c7fedad072a76e2bbd67190bd2c0f651529 /editors | |
parent | caa93ecdd3a9b998a69dcbfafdddbc9c58887ec3 (diff) | |
download | busybox-8d269ef85984f6476e7fdbec2c5a70f3b5c48a72.zip busybox-8d269ef85984f6476e7fdbec2c5a70f3b5c48a72.tar.gz |
awk: fix printf "%-10c", 0
function old new delta
awk_printf 596 626 +30
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'editors')
-rw-r--r-- | editors/awk.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/editors/awk.c b/editors/awk.c index 465033f..437d87e 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -2360,10 +2360,11 @@ static char *awk_printf(node *n, size_t *len) */ if (c == 'c') { char cc = is_numeric(arg) ? getvar_i(arg) : *getvar_s(arg); - s = xasprintf(s, cc); - /* + 1 if cc == NUL: handle printf "%c" 0 case - * (and printf "%22c" 0 etc, but still fails for e.g. printf "%-22c" 0) */ - slen = strlen(s) + (cc == '\0'); + char *r = xasprintf(s, cc ? cc : '^' /* else strlen will be wrong */); + slen = strlen(r); + if (cc == '\0') /* if cc is NUL, re-format the string with it */ + sprintf(r, s, cc); + s = r; } else { if (c == 's') { s = xasprintf(s, getvar_s(arg)); |