bc: fix keyword matching to not think "ifz" is the "if" keyword
authorDenys Vlasenko <vda.linux@googlemail.com>
Thu, 20 Dec 2018 15:48:50 +0000 (16:48 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 20 Dec 2018 15:48:50 +0000 (16:48 +0100)
function                                             old     new   delta
zbc_lex_next                                        2224    2225      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
miscutils/bc.c
testsuite/bc.tests

index c5288102d1d7b8d448578afd6812e3d118533e98..1e2ca8b83f9b83cfb848d17cfe5b0aa3c8a38140 100644 (file)
@@ -2950,6 +2950,8 @@ static BC_STATUS zbc_lex_identifier(BcLex *l)
                        continue;
  match:
                // buf starts with keyword bc_lex_kws[i]
+               if (isalnum(buf[j]) || buf[j]=='_')
+                       continue; // "ifz" does not match "if" keyword, "if." does
                l->t.t = BC_LEX_KEY_1st_keyword + i;
                if (!bc_lex_kws_POSIX(i)) {
                        s = bc_posix_error_fmt("%sthe '%.8s' keyword", "POSIX does not allow ", bc_lex_kws[i].name8);
index e303cf6ae2de144bae71503bf7b8af568aedadf5..d33f8c90ae14e7562c272c83b2b95874a084746a 100755 (executable)
@@ -76,6 +76,11 @@ testing "bc while(cond)<NL>" \
        "8\n7\n6\n5\n4\n3\n2\n1\n9\n" \
        "" "i=9;while(--i)\ni\n9"
 
+testing "bc ifz does not match if keyword" \
+       "bc" \
+       "1\n2\n2\n3\n" \
+       "" "ifz=1;ifz\n++ifz;ifz++\nifz"
+
 testing "bc print 1,2,3" \
        "bc" \
        "123" \