← Commit list

55f3cab7e

Denys Vlasenko
Denys Vlasenko
2018-12-18
SUCCESS Duration: 151s

Subject

bc: fix "echo -n '#foo' | bc" not eating last 'o'

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

miscutils/bc.c+7 -3
@@ -2655,9 +2655,13 @@ static FAST_FUNC void bc_result_free(void *result)
static void bc_lex_lineComment(BcLex *l)
{
+ // Try: echo -n '#foo' | bc
+ size_t i;
l->t.t = BC_LEX_WHITESPACE;
- while (l->i < l->len && l->buf[l->i++] != '\n');
- --l->i;
+ i = l->i;
+ while (i < l->len && l->buf[i] != '\n')
+ i++;
+ l->i = i;
}
static void bc_lex_whitespace(BcLex *l)
@@ -2889,8 +2893,8 @@ static BC_STATUS zbc_lex_next(BcLex *l)
// Comments are also BC_LEX_WHITESPACE tokens and eaten here.
s = BC_STATUS_SUCCESS;
do {
- l->t.t = BC_LEX_EOF;
if (l->i == l->len) {
+ l->t.t = BC_LEX_EOF;
if (!G.input_fp)
RETURN_STATUS(BC_STATUS_SUCCESS);
if (!bc_lex_more_input(l)) {
testsuite/bc.tests+5 -0
@@ -16,6 +16,11 @@ testing "bc comment 2: /*/ is not a closed comment" \
"4\n" \
"" "1 /*/ + 2 */ + 3"
+testing "bc comment 3: unterminated #comment" \
+ "bc" \
+ "" \
+ "" "#foo" # no trailing newline
+
testing "bc backslash 1" \
"bc" \
"3\n" \