← Commit list

7d06d6e18

Daniel Thau
Daniel Thau
2021-09-05
SUCCESS Duration: 154s

Subject

awk: fix printf %%

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

editors/awk.c+8 -1
@@ -2346,8 +2346,15 @@ static char *awk_printf(node *n, size_t *len)
size_t slen;
s = f;
- while (*f && (*f != '%' || *++f == '%'))
+ while (*f && *f != '%')
f++;
+ c = *++f;
+ if (c == '%') { /* double % */
+ slen = f - s;
+ s = xstrndup(s, slen);
+ f++;
+ goto tail;
+ }
while (*f && !isalpha(*f)) {
if (*f == '*')
syntax_error("%*x formats are not supported");
testsuite/awk.tests+6 -0
@@ -463,4 +463,10 @@ testing "awk \"cmd\" | getline" \
"HELLO\n" \
'' ''
+# printf %% should print one % (had a bug where it didn't)
+testing 'awk printf %% prints one %' \
+ "awk 'BEGIN { printf \"%%\n\" }'" \
+ "%\n" \
+ '' ''
+
exit $FAILCOUNT
testsuite/printf.tests+5 -0
@@ -79,6 +79,11 @@ testing "printf understands %Ld" \
"-5\n""0\n" \
"" ""
+testing "printf understands %%" \
+ "${bb}printf '%%\n' 2>&1; echo \$?" \
+ "%\n""0\n" \
+ "" ""
+
testing "printf handles positive numbers for %d" \
"${bb}printf '%d\n' 3 +3 ' 3' ' +3' 2>&1; echo \$?" \
"3\n"\