bc: fix comment handling
authorDenys Vlasenko <vda.linux@googlemail.com>
Thu, 13 Dec 2018 16:23:24 +0000 (17:23 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 13 Dec 2018 16:43:23 +0000 (17:43 +0100)
function                                             old     new   delta
bc_vm_run                                            514     513      -1

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

index 9c7e69fc182795dc08fc9b9ced2273dc39f79efe..dc9a7da8e3b9b3f98206685a011fdee005c0ef1a 100644 (file)
@@ -7088,10 +7088,13 @@ static BC_STATUS zbc_vm_stdin(void)
                                string++;
                                if (c == '/' && *string == '*') {
                                        comment = true;
-                                       break;
+                                       string++;
+                                       continue;
                                }
-                               if (c == '*' && *string == '/')
+                               if (c == '*' && *string == '/') {
                                        comment = false;
+                                       string++;
+                               }
                        }
                        if (str || comment || string[-2] == '\\') {
                                bc_vec_concat(&buffer, buf.v);
index 32460092bc3561d52cc25f234c36f79593de81fc..4f0d50f73d0b1befdc9eb8cf76075cbc638a8918 100755 (executable)
@@ -4,6 +4,18 @@
 
 . ./testing.sh
 
+# testing "test name" "command" "expected result" "file input" "stdin"
+
+testing "bc comment 1" \
+       "bc" \
+       "3\n" \
+       "" "1 /* comment */ + 2"
+
+testing "bc comment 2: /*/ is not a closed comment" \
+       "bc" \
+       "4\n" \
+       "" "1 /*/ + 2 */ + 3"
+
 tar xJf bc_large.tar.xz
 
 for f in bc*.bc; do