aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--miscutils/bc.c10
-rwxr-xr-xtestsuite/bc.tests5
2 files changed, 12 insertions, 3 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index a5fcaf3bc..eaa28a94a 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -2655,9 +2655,13 @@ static FAST_FUNC void bc_result_free(void *result)
2655 2655
2656static void bc_lex_lineComment(BcLex *l) 2656static void bc_lex_lineComment(BcLex *l)
2657{ 2657{
2658 // Try: echo -n '#foo' | bc
2659 size_t i;
2658 l->t.t = BC_LEX_WHITESPACE; 2660 l->t.t = BC_LEX_WHITESPACE;
2659 while (l->i < l->len && l->buf[l->i++] != '\n'); 2661 i = l->i;
2660 --l->i; 2662 while (i < l->len && l->buf[i] != '\n')
2663 i++;
2664 l->i = i;
2661} 2665}
2662 2666
2663static void bc_lex_whitespace(BcLex *l) 2667static void bc_lex_whitespace(BcLex *l)
@@ -2889,8 +2893,8 @@ static BC_STATUS zbc_lex_next(BcLex *l)
2889 // Comments are also BC_LEX_WHITESPACE tokens and eaten here. 2893 // Comments are also BC_LEX_WHITESPACE tokens and eaten here.
2890 s = BC_STATUS_SUCCESS; 2894 s = BC_STATUS_SUCCESS;
2891 do { 2895 do {
2892 l->t.t = BC_LEX_EOF;
2893 if (l->i == l->len) { 2896 if (l->i == l->len) {
2897 l->t.t = BC_LEX_EOF;
2894 if (!G.input_fp) 2898 if (!G.input_fp)
2895 RETURN_STATUS(BC_STATUS_SUCCESS); 2899 RETURN_STATUS(BC_STATUS_SUCCESS);
2896 if (!bc_lex_more_input(l)) { 2900 if (!bc_lex_more_input(l)) {
diff --git a/testsuite/bc.tests b/testsuite/bc.tests
index e0a45a8bd..e303cf6ae 100755
--- a/testsuite/bc.tests
+++ b/testsuite/bc.tests
@@ -16,6 +16,11 @@ 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
19testing "bc comment 3: unterminated #comment" \
20 "bc" \
21 "" \
22 "" "#foo" # no trailing newline
23
19testing "bc backslash 1" \ 24testing "bc backslash 1" \
20 "bc" \ 25 "bc" \
21 "3\n" \ 26 "3\n" \