← Commit list

6f7a00964

Denys Vlasenko
Denys Vlasenko
2020-06-09
SUCCESS Duration: 153s

Subject

awk: disallow "str"++, closes bug 12981

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+3 -1
@@ -1359,8 +1359,10 @@ static node *parse_expr(uint32_t iexp)
v = cn->l.v = xzalloc(sizeof(var));
if (tc & TC_NUMBER)
setvar_i(v, t_double);
- else
+ else {
setvar_s(v, t_string);
+ xtc &= ~TC_UOPPOST; /* "str"++ is not allowed */
+ }
break;
case TC_REGEXP:
testsuite/awk.tests+8 -0
@@ -390,5 +390,13 @@ testing 'awk negative field access' \
'' \
'anything'
+# was misinterpreted as (("str"++) i) instead of ("str" (++i))
+# (and was executed: "str"++ is "0", thus concatenating "0" and "1"):
+testing 'awk do not allow "str"++' \
+ 'awk -v i=1 "BEGIN {print \"str\" ++i}"' \
+ "str2\n" \
+ '' \
+ 'anything'
+
exit $FAILCOUNT