diff options
-rw-r--r-- | miscutils/bc.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 171bc8858..97adeaa53 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -1068,6 +1068,13 @@ static void bc_vec_pushByte(BcVec *v, char data) | |||
1068 | bc_vec_push(v, &data); | 1068 | bc_vec_push(v, &data); |
1069 | } | 1069 | } |
1070 | 1070 | ||
1071 | static void bc_vec_pushZeroByte(BcVec *v) | ||
1072 | { | ||
1073 | //bc_vec_pushByte(v, '\0'); | ||
1074 | // better: | ||
1075 | bc_vec_push(v, &const_int_0); | ||
1076 | } | ||
1077 | |||
1071 | static void bc_vec_pushAt(BcVec *v, const void *data, size_t idx) | 1078 | static void bc_vec_pushAt(BcVec *v, const void *data, size_t idx) |
1072 | { | 1079 | { |
1073 | if (idx == v->len) | 1080 | if (idx == v->len) |
@@ -1092,14 +1099,14 @@ static void bc_vec_string(BcVec *v, size_t len, const char *str) | |||
1092 | memcpy(v->v, str, len); | 1099 | memcpy(v->v, str, len); |
1093 | v->len = len; | 1100 | v->len = len; |
1094 | 1101 | ||
1095 | bc_vec_pushByte(v, '\0'); | 1102 | bc_vec_pushZeroByte(v); |
1096 | } | 1103 | } |
1097 | 1104 | ||
1098 | static void bc_vec_concat(BcVec *v, const char *str) | 1105 | static void bc_vec_concat(BcVec *v, const char *str) |
1099 | { | 1106 | { |
1100 | size_t len; | 1107 | size_t len; |
1101 | 1108 | ||
1102 | if (v->len == 0) bc_vec_pushByte(v, '\0'); | 1109 | if (v->len == 0) bc_vec_pushZeroByte(v); |
1103 | 1110 | ||
1104 | len = v->len + strlen(str); | 1111 | len = v->len + strlen(str); |
1105 | 1112 | ||
@@ -1173,7 +1180,6 @@ static BcStatus bc_read_line(BcVec *vec, const char *prompt) | |||
1173 | 1180 | ||
1174 | do { | 1181 | do { |
1175 | int i; | 1182 | int i; |
1176 | char c; | ||
1177 | 1183 | ||
1178 | bad_chars = 0; | 1184 | bad_chars = 0; |
1179 | bc_vec_pop_all(vec); | 1185 | bc_vec_pop_all(vec); |
@@ -1222,12 +1228,11 @@ static BcStatus bc_read_line(BcVec *vec, const char *prompt) | |||
1222 | bc_error_fmt("illegal character 0x%02x", i); | 1228 | bc_error_fmt("illegal character 0x%02x", i); |
1223 | bad_chars = 1; | 1229 | bad_chars = 1; |
1224 | } | 1230 | } |
1225 | c = (char) i; | 1231 | bc_vec_pushByte(vec, (char)i); |
1226 | bc_vec_push(vec, &c); | ||
1227 | } while (i != '\n'); | 1232 | } while (i != '\n'); |
1228 | } while (bad_chars); | 1233 | } while (bad_chars); |
1229 | 1234 | ||
1230 | bc_vec_pushByte(vec, '\0'); | 1235 | bc_vec_pushZeroByte(vec); |
1231 | 1236 | ||
1232 | return BC_STATUS_SUCCESS; | 1237 | return BC_STATUS_SUCCESS; |
1233 | } | 1238 | } |
@@ -2833,7 +2838,7 @@ static BcStatus bc_lex_number(BcLex *l, char start) | |||
2833 | bc_vec_push(&l->t.v, &c); | 2838 | bc_vec_push(&l->t.v, &c); |
2834 | } | 2839 | } |
2835 | 2840 | ||
2836 | bc_vec_pushByte(&l->t.v, '\0'); | 2841 | bc_vec_pushZeroByte(&l->t.v); |
2837 | l->i += i; | 2842 | l->i += i; |
2838 | 2843 | ||
2839 | return BC_STATUS_SUCCESS; | 2844 | return BC_STATUS_SUCCESS; |
@@ -3307,7 +3312,7 @@ static BcStatus dc_lex_register(BcLex *l) | |||
3307 | else { | 3312 | else { |
3308 | bc_vec_pop_all(&l->t.v); | 3313 | bc_vec_pop_all(&l->t.v); |
3309 | bc_vec_pushByte(&l->t.v, l->buf[l->i - 1]); | 3314 | bc_vec_pushByte(&l->t.v, l->buf[l->i - 1]); |
3310 | bc_vec_pushByte(&l->t.v, '\0'); | 3315 | bc_vec_pushZeroByte(&l->t.v); |
3311 | l->t.t = BC_LEX_NAME; | 3316 | l->t.t = BC_LEX_NAME; |
3312 | } | 3317 | } |
3313 | 3318 | ||
@@ -3336,7 +3341,7 @@ static BcStatus dc_lex_string(BcLex *l) | |||
3336 | return bc_error("string end could not be found"); | 3341 | return bc_error("string end could not be found"); |
3337 | } | 3342 | } |
3338 | 3343 | ||
3339 | bc_vec_pushByte(&l->t.v, '\0'); | 3344 | bc_vec_pushZeroByte(&l->t.v); |
3340 | if (i - l->i > BC_MAX_STRING) | 3345 | if (i - l->i > BC_MAX_STRING) |
3341 | return bc_error("string too long: must be [1, BC_STRING_MAX]"); | 3346 | return bc_error("string too long: must be [1, BC_STRING_MAX]"); |
3342 | 3347 | ||
@@ -3558,7 +3563,7 @@ static void bc_parse_create(BcParse *p, size_t func, | |||
3558 | bc_vec_init(&p->flags, sizeof(uint8_t), NULL); | 3563 | bc_vec_init(&p->flags, sizeof(uint8_t), NULL); |
3559 | bc_vec_init(&p->exits, sizeof(BcInstPtr), NULL); | 3564 | bc_vec_init(&p->exits, sizeof(BcInstPtr), NULL); |
3560 | bc_vec_init(&p->conds, sizeof(size_t), NULL); | 3565 | bc_vec_init(&p->conds, sizeof(size_t), NULL); |
3561 | bc_vec_pushByte(&p->flags, 0); | 3566 | bc_vec_pushZeroByte(&p->flags); |
3562 | bc_vec_init(&p->ops, sizeof(BcLexType), NULL); | 3567 | bc_vec_init(&p->ops, sizeof(BcLexType), NULL); |
3563 | 3568 | ||
3564 | p->parse = parse; | 3569 | p->parse = parse; |
@@ -6915,7 +6920,7 @@ static BcStatus bc_vm_stdin(void) | |||
6915 | 6920 | ||
6916 | bc_char_vec_init(&buffer); | 6921 | bc_char_vec_init(&buffer); |
6917 | bc_char_vec_init(&buf); | 6922 | bc_char_vec_init(&buf); |
6918 | bc_vec_pushByte(&buffer, '\0'); | 6923 | bc_vec_pushZeroByte(&buffer); |
6919 | 6924 | ||
6920 | // This loop is complex because the vm tries not to send any lines that end | 6925 | // This loop is complex because the vm tries not to send any lines that end |
6921 | // with a backslash to the parser. The reason for that is because the parser | 6926 | // with a backslash to the parser. The reason for that is because the parser |