[git commit] awk: fix corner case in awk_printf
Denys Vlasenko
vda.linux at googlemail.com
Sun Jul 11 16:16:10 UTC 2021
commit: https://git.busybox.net/busybox/commit/?id=caa93ecdd3a9b998a69dcbfafdddbc9c58887ec3
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master
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 at googlemail.com>
---
editors/awk.c | 8 ++++----
1 file 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)
* printf "%99999s", "BOOM"
*/
if (c == 'c') {
- c = is_numeric(arg) ? getvar_i(arg) : *getvar_s(arg);
- s = xasprintf(s, c);
- /* + 1 if c == NUL: handle printf "%c" 0 case
+ 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) + (c == '\0');
+ slen = strlen(s) + (cc == '\0');
} else {
if (c == 's') {
s = xasprintf(s, getvar_s(arg));
More information about the busybox-cvs
mailing list