diff options
-rw-r--r-- | miscutils/bc.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 143bb64b1..32e002913 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -1358,6 +1358,8 @@ static int push_input_byte(BcVec *vec, char c) | |||
1358 | } | 1358 | } |
1359 | 1359 | ||
1360 | // This is not a "z" function: can also return BC_STATUS_EOF | 1360 | // This is not a "z" function: can also return BC_STATUS_EOF |
1361 | // Can return success (0) or BC_STATUS_EOF. | ||
1362 | // Exits with error message if read error is detected. | ||
1361 | static BcStatus bc_read_line(BcVec *vec) | 1363 | static BcStatus bc_read_line(BcVec *vec) |
1362 | { | 1364 | { |
1363 | BcStatus s; | 1365 | BcStatus s; |
@@ -5523,7 +5525,7 @@ static BcStatus bc_program_read(void) | |||
5523 | G.prog.file = NULL; | 5525 | G.prog.file = NULL; |
5524 | 5526 | ||
5525 | s = bc_read_line(&buf); | 5527 | s = bc_read_line(&buf); |
5526 | if (s) goto io_err; | 5528 | //if (s) goto io_err; - wrong, nonzero return means EOF, not error |
5527 | 5529 | ||
5528 | common_parse_init(&parse, BC_PROG_READ); | 5530 | common_parse_init(&parse, BC_PROG_READ); |
5529 | bc_lex_file(&parse.l); | 5531 | bc_lex_file(&parse.l); |
@@ -5549,9 +5551,9 @@ static BcStatus bc_program_read(void) | |||
5549 | bc_vec_push(&G.prog.stack, &ip); | 5551 | bc_vec_push(&G.prog.stack, &ip); |
5550 | 5552 | ||
5551 | exec_err: | 5553 | exec_err: |
5552 | G.prog.file = sv_file; | ||
5553 | bc_parse_free(&parse); | 5554 | bc_parse_free(&parse); |
5554 | io_err: | 5555 | //io_err: |
5556 | G.prog.file = sv_file; | ||
5555 | bc_vec_free(&buf); | 5557 | bc_vec_free(&buf); |
5556 | return s; | 5558 | return s; |
5557 | } | 5559 | } |
@@ -7171,8 +7173,8 @@ static BcStatus bc_vm_stdin(void) | |||
7171 | { | 7173 | { |
7172 | BcStatus s; | 7174 | BcStatus s; |
7173 | BcVec buf, buffer; | 7175 | BcVec buf, buffer; |
7174 | size_t len, i, str = 0; | 7176 | size_t str; |
7175 | bool comment = false; | 7177 | bool comment; |
7176 | 7178 | ||
7177 | G.prog.file = NULL; | 7179 | G.prog.file = NULL; |
7178 | bc_lex_file(&G.prs.l); | 7180 | bc_lex_file(&G.prs.l); |
@@ -7185,12 +7187,13 @@ static BcStatus bc_vm_stdin(void) | |||
7185 | // with a backslash to the parser. The reason for that is because the parser | 7187 | // with a backslash to the parser. The reason for that is because the parser |
7186 | // treats a backslash+newline combo as whitespace, per the bc spec. In that | 7188 | // treats a backslash+newline combo as whitespace, per the bc spec. In that |
7187 | // case, and for strings and comments, the parser will expect more stuff. | 7189 | // case, and for strings and comments, the parser will expect more stuff. |
7190 | comment = false; | ||
7191 | str = 0; | ||
7188 | while ((s = bc_read_line(&buf)) == BC_STATUS_SUCCESS) { | 7192 | while ((s = bc_read_line(&buf)) == BC_STATUS_SUCCESS) { |
7189 | 7193 | size_t len; | |
7190 | char *string = buf.v; | 7194 | char *string = buf.v; |
7191 | 7195 | ||
7192 | len = buf.len - 1; | 7196 | len = buf.len - 1; |
7193 | |||
7194 | if (len == 1) { | 7197 | if (len == 1) { |
7195 | if (str && buf.v[0] == G.send) | 7198 | if (str && buf.v[0] == G.send) |
7196 | str -= 1; | 7199 | str -= 1; |
@@ -7198,9 +7201,8 @@ static BcStatus bc_vm_stdin(void) | |||
7198 | str += 1; | 7201 | str += 1; |
7199 | } | 7202 | } |
7200 | else if (len > 1 || comment) { | 7203 | else if (len > 1 || comment) { |
7201 | 7204 | size_t i; | |
7202 | for (i = 0; i < len; ++i) { | 7205 | for (i = 0; i < len; ++i) { |
7203 | |||
7204 | bool notend = len > i + 1; | 7206 | bool notend = len > i + 1; |
7205 | char c = string[i]; | 7207 | char c = string[i]; |
7206 | 7208 | ||