bc: fix another thinko
authorDenys Vlasenko <vda.linux@googlemail.com>
Thu, 13 Dec 2018 16:56:35 +0000 (17:56 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 13 Dec 2018 16:56:35 +0000 (17:56 +0100)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
miscutils/bc.c
testsuite/bc.tests

index a78cd591ad1e71c412ba114afb4881febcecdf23..74847a32812c83fbc873085cdf01fcb034e368ef 100644 (file)
@@ -7059,22 +7059,21 @@ static BC_STATUS zbc_vm_stdin(void)
        str = 0;
        for (;;) {
                size_t len;
-               char *string;
 
                bc_read_line(&buf);
                len = buf.len - 1;
                if (len == 0) // "" buf means EOF
                        break;
-               string = buf.v;
                if (len == 1) {
                        if (str && buf.v[0] == G.send)
                                str -= 1;
                        else if (buf.v[0] == G.sbgn)
                                str += 1;
                } else {
+                       char *string = buf.v;
                        while (*string) {
                                char c = *string;
-                               if (string != buf.v && string[-1] != '\\') {
+                               if (string == buf.v || string[-1] != '\\') {
                                        // checking applet type is cheaper than accessing sbgn/send
                                        if (IS_BC) // bc: sbgn = send = '"'
                                                str ^= (c == '"');
index 4f0d50f73d0b1befdc9eb8cf76075cbc638a8918..5e8c47c0fbf0f3034f0c58cc6567bcecdbf28ec6 100755 (executable)
@@ -16,6 +16,16 @@ testing "bc comment 2: /*/ is not a closed comment" \
        "4\n" \
        "" "1 /*/ + 2 */ + 3"
 
+testing "bc backslash 1" \
+       "bc" \
+       "3\n" \
+       "" "1 \\\\\n + 2"
+
+testing "bc string 1" \
+       "bc" \
+       "STR\n" \
+       "" "\"STR\n\""
+
 tar xJf bc_large.tar.xz
 
 for f in bc*.bc; do