diff options
| -rw-r--r-- | miscutils/bc.c | 5 | ||||
| -rwxr-xr-x | testsuite/bc.tests | 10 |
2 files changed, 12 insertions, 3 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index a78cd591a..74847a328 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
| @@ -7059,22 +7059,21 @@ static BC_STATUS zbc_vm_stdin(void) | |||
| 7059 | str = 0; | 7059 | str = 0; |
| 7060 | for (;;) { | 7060 | for (;;) { |
| 7061 | size_t len; | 7061 | size_t len; |
| 7062 | char *string; | ||
| 7063 | 7062 | ||
| 7064 | bc_read_line(&buf); | 7063 | bc_read_line(&buf); |
| 7065 | len = buf.len - 1; | 7064 | len = buf.len - 1; |
| 7066 | if (len == 0) // "" buf means EOF | 7065 | if (len == 0) // "" buf means EOF |
| 7067 | break; | 7066 | break; |
| 7068 | string = buf.v; | ||
| 7069 | if (len == 1) { | 7067 | if (len == 1) { |
| 7070 | if (str && buf.v[0] == G.send) | 7068 | if (str && buf.v[0] == G.send) |
| 7071 | str -= 1; | 7069 | str -= 1; |
| 7072 | else if (buf.v[0] == G.sbgn) | 7070 | else if (buf.v[0] == G.sbgn) |
| 7073 | str += 1; | 7071 | str += 1; |
| 7074 | } else { | 7072 | } else { |
| 7073 | char *string = buf.v; | ||
| 7075 | while (*string) { | 7074 | while (*string) { |
| 7076 | char c = *string; | 7075 | char c = *string; |
| 7077 | if (string != buf.v && string[-1] != '\\') { | 7076 | if (string == buf.v || string[-1] != '\\') { |
| 7078 | // checking applet type is cheaper than accessing sbgn/send | 7077 | // checking applet type is cheaper than accessing sbgn/send |
| 7079 | if (IS_BC) // bc: sbgn = send = '"' | 7078 | if (IS_BC) // bc: sbgn = send = '"' |
| 7080 | str ^= (c == '"'); | 7079 | str ^= (c == '"'); |
diff --git a/testsuite/bc.tests b/testsuite/bc.tests index 4f0d50f73..5e8c47c0f 100755 --- a/testsuite/bc.tests +++ b/testsuite/bc.tests | |||
| @@ -16,6 +16,16 @@ testing "bc comment 2: /*/ is not a closed comment" \ | |||
| 16 | "4\n" \ | 16 | "4\n" \ |
| 17 | "" "1 /*/ + 2 */ + 3" | 17 | "" "1 /*/ + 2 */ + 3" |
| 18 | 18 | ||
| 19 | testing "bc backslash 1" \ | ||
| 20 | "bc" \ | ||
| 21 | "3\n" \ | ||
| 22 | "" "1 \\\\\n + 2" | ||
| 23 | |||
| 24 | testing "bc string 1" \ | ||
| 25 | "bc" \ | ||
| 26 | "STR\n" \ | ||
| 27 | "" "\"STR\n\"" | ||
| 28 | |||
| 19 | tar xJf bc_large.tar.xz | 29 | tar xJf bc_large.tar.xz |
| 20 | 30 | ||
| 21 | for f in bc*.bc; do | 31 | for f in bc*.bc; do |
