aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/awk.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/editors/awk.c b/editors/awk.c
index 465033f5f..437d87ecf 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -2360,10 +2360,11 @@ static char *awk_printf(node *n, size_t *len)
2360 */ 2360 */
2361 if (c == 'c') { 2361 if (c == 'c') {
2362 char cc = 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, cc); 2363 char *r = xasprintf(s, cc ? cc : '^' /* else strlen will be wrong */);
2364 /* + 1 if cc == NUL: handle printf "%c" 0 case 2364 slen = strlen(r);
2365 * (and printf "%22c" 0 etc, but still fails for e.g. printf "%-22c" 0) */ 2365 if (cc == '\0') /* if cc is NUL, re-format the string with it */
2366 slen = strlen(s) + (cc == '\0'); 2366 sprintf(r, s, cc);
2367 s = r;
2367 } else { 2368 } else {
2368 if (c == 's') { 2369 if (c == 's') {
2369 s = xasprintf(s, getvar_s(arg)); 2370 s = xasprintf(s, getvar_s(arg));