diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-25 23:45:57 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-25 23:45:57 +0100 |
commit | 94576d2b972b3bd136fbe8057c95690ae36ea8c9 (patch) | |
tree | cc1b99c8e3fb95448b7595fea6b141516894cf40 | |
parent | c192b0442b0b3f50d4fbb34322e07f0ff3c5aecd (diff) | |
download | busybox-w32-94576d2b972b3bd136fbe8057c95690ae36ea8c9.tar.gz busybox-w32-94576d2b972b3bd136fbe8057c95690ae36ea8c9.tar.bz2 busybox-w32-94576d2b972b3bd136fbe8057c95690ae36ea8c9.zip |
bc: fix interactive handling of comments in strings and quotes in comments
function old new delta
zbc_lex_next 1965 1979 +14
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/bc.c | 36 | ||||
-rwxr-xr-x | testsuite/bc.tests | 16 |
2 files changed, 34 insertions, 18 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 809b4bfc4..9d04ddea3 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -2910,25 +2910,29 @@ static bool bc_lex_more_input(void) | |||
2910 | string = G.input_buffer.v + prevlen; | 2910 | string = G.input_buffer.v + prevlen; |
2911 | while (*string) { | 2911 | while (*string) { |
2912 | char c = *string; | 2912 | char c = *string; |
2913 | if (string == G.input_buffer.v || string[-1] != '\\') { | 2913 | if (!comment) { |
2914 | if (IS_BC) | 2914 | if (string == G.input_buffer.v || string[-1] != '\\') { |
2915 | str ^= (c == '"'); | 2915 | if (IS_BC) |
2916 | else { | 2916 | str ^= (c == '"'); |
2917 | if (c == ']') | 2917 | else { |
2918 | str -= 1; | 2918 | if (c == ']') |
2919 | else if (c == '[') | 2919 | str -= 1; |
2920 | str += 1; | 2920 | else if (c == '[') |
2921 | str += 1; | ||
2922 | } | ||
2921 | } | 2923 | } |
2922 | } | 2924 | } |
2923 | string++; | 2925 | string++; |
2924 | if (c == '/' && *string == '*') { | 2926 | if (!str) { |
2925 | comment = true; | 2927 | if (c == '/' && *string == '*') { |
2926 | string++; | 2928 | comment = true; |
2927 | continue; | 2929 | string++; |
2928 | } | 2930 | continue; |
2929 | if (c == '*' && *string == '/') { | 2931 | } |
2930 | comment = false; | 2932 | if (c == '*' && *string == '/') { |
2931 | string++; | 2933 | comment = false; |
2934 | string++; | ||
2935 | } | ||
2932 | } | 2936 | } |
2933 | } | 2937 | } |
2934 | if (str != 0 || comment) { | 2938 | if (str != 0 || comment) { |
diff --git a/testsuite/bc.tests b/testsuite/bc.tests index 42fe83013..3fbb49996 100755 --- a/testsuite/bc.tests +++ b/testsuite/bc.tests | |||
@@ -6,16 +6,28 @@ | |||
6 | 6 | ||
7 | # testing "test name" "command" "expected result" "file input" "stdin" | 7 | # testing "test name" "command" "expected result" "file input" "stdin" |
8 | 8 | ||
9 | testing "bc comment 1" \ | 9 | testing "bc comment" \ |
10 | "bc" \ | 10 | "bc" \ |
11 | "3\n" \ | 11 | "3\n" \ |
12 | "" "1 /* comment */ + 2" | 12 | "" "1 /* comment */ + 2" |
13 | 13 | ||
14 | testing "bc comment 2: /*/ is not a closed comment" \ | 14 | testing "bc /*/ is not a closed comment" \ |
15 | "bc" \ | 15 | "bc" \ |
16 | "4\n" \ | 16 | "4\n" \ |
17 | "" "1 /*/ + 2 */ + 3" | 17 | "" "1 /*/ + 2 */ + 3" |
18 | 18 | ||
19 | # this needs interactive testing | ||
20 | testing "bc comment with \"" \ | ||
21 | "bc" \ | ||
22 | "3\n" \ | ||
23 | "" "1 /* \" */ + 2" | ||
24 | |||
25 | # this needs interactive testing | ||
26 | testing "bc \"string/*\" is not a comment" \ | ||
27 | "bc" \ | ||
28 | "string/*9\n" \ | ||
29 | "" "\"string/*\";9" | ||
30 | |||
19 | testing "bc comment 3: unterminated #comment" \ | 31 | testing "bc comment 3: unterminated #comment" \ |
20 | "bc" \ | 32 | "bc" \ |
21 | "" \ | 33 | "" \ |