summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2023-05-29 10:55:40 +0200
committerDenys Vlasenko2023-05-29 10:55:40 +0200
commit721bf6eaf4739a2865b071b38d3478f334234d26 (patch)
treef5c5779522dc246b33186022ab54dcfd2f9902a9
parent4d7339204f9f823f592562d9903db3ae79a6c640 (diff)
downloadbusybox-721bf6eaf4739a2865b071b38d3478f334234d26.zip
busybox-721bf6eaf4739a2865b071b38d3478f334234d26.tar.gz
awk: printf(INVALID_FMT) prints it verbatim
function old new delta awk_printf 628 640 +12 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--editors/awk.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/editors/awk.c b/editors/awk.c
index b5774a3..c49ad6e 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);