awk: never return NULL from awk_printf()

function                                             old     new   delta
awk_printf                                           651     628     -23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2021-09-09 19:26:39 +02:00
parent e60c56932e
commit 857800c655

View File

@ -2338,7 +2338,7 @@ static char *awk_printf(node *n, size_t *len)
b = NULL; b = NULL;
i = 0; i = 0;
while (*f) { /* "print one format spec" loop */ while (1) { /* "print one format spec" loop */
char *s; char *s;
char c; char c;
char sv; char sv;
@ -2363,7 +2363,7 @@ static char *awk_printf(node *n, size_t *len)
slen = f - s; slen = f - s;
s = xstrndup(s, slen); s = xstrndup(s, slen);
f++; f++;
goto tail; /* print "....%" part verbatim */ goto append; /* print "....%" part verbatim */
} }
while (1) { while (1) {
if (isalpha(c)) if (isalpha(c))
@ -2412,7 +2412,7 @@ static char *awk_printf(node *n, size_t *len)
slen = strlen(s); slen = strlen(s);
} }
*f = sv; *f = sv;
append:
if (i == 0) { if (i == 0) {
b = s; b = s;
i = slen; i = slen;
@ -2422,7 +2422,7 @@ static char *awk_printf(node *n, size_t *len)
b = xrealloc(b, i + slen + 1); b = xrealloc(b, i + slen + 1);
strcpy(b + i, s); strcpy(b + i, s);
i += slen; i += slen;
if (!c) /* tail? */ if (!c) /* s is NOT allocated and this is the last part of string? */
break; break;
free(s); free(s);
} }