[git commit] awk: printf(INVALID_FMT) prints it verbatim
Denys Vlasenko
vda.linux at googlemail.com
Mon May 29 08:55:40 UTC 2023
commit: https://git.busybox.net/busybox/commit/?id=721bf6eaf4739a2865b071b38d3478f334234d26
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master
function old new delta
awk_printf 628 640 +12
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
editors/awk.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/editors/awk.c b/editors/awk.c
index b5774a339..c49ad6e02 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -2389,7 +2389,7 @@ static char *awk_printf(node *n, size_t *len)
while (1) {
if (isalpha(c))
break;
- if (c == '*')
+ if (c == '*') /* gawk supports %*d and %*.*f, we don't... */
syntax_error("%*x formats are not supported");
c = *++f;
if (!c) { /* "....%...." and no letter found after % */
@@ -2422,12 +2422,18 @@ static char *awk_printf(node *n, size_t *len)
double d = getvar_i(arg);
if (strchr("diouxX", c)) {
//TODO: make it wider here (%x -> %llx etc)?
+//Can even print the value into a temp string with %.0f,
+//then replace diouxX with s and print that string.
+//This will correctly print even very large numbers,
+//but some replacements are not equivalent:
+//%09d -> %09s: breaks zero-padding;
+//%+d -> %+s: won't prepend +; etc
s = xasprintf(s, (int)d);
} else if (strchr("eEfFgGaA", c)) {
s = xasprintf(s, d);
} else {
-//TODO: GNU Awk 5.0.1: printf "%W" prints "%W", does not error out
- syntax_error(EMSG_INV_FMT);
+ /* gawk 5.1.1 printf("%W") prints "%W", does not error out */
+ s = xstrndup(s, f - s);
}
}
slen = strlen(s);
More information about the busybox-cvs
mailing list