Fix bugs found when running tests
diff --git a/src/bc/num.c b/src/bc/num.c
index 74ecc71..fae246e 100644
--- a/src/bc/num.c
+++ b/src/bc/num.c
@@ -713,6 +713,8 @@
status = bc_num_expand(n, len);
if (status) return status;
+
+ memset(n->num, 0, sizeof(char) * len);
}
else {
diff --git a/src/bc/parse.c b/src/bc/parse.c
index 88bb97e..60b521e 100644
--- a/src/bc/parse.c
+++ b/src/bc/parse.c
@@ -1240,8 +1240,6 @@
return status;
}
- free(parse->token.string);
-
paren_expr = true;
rparen = false;
get_token = true;
diff --git a/src/bc/program.c b/src/bc/program.c
index 380516c..9534f54 100644
--- a/src/bc/program.c
+++ b/src/bc/program.c
@@ -199,18 +199,30 @@
}
#endif
- s = bc_num_parse(&p->last, "0", 10, 0);
+ s = bc_num_construct(&p->last, BC_NUM_DEF_SIZE);
if (s) return s;
- s = bc_num_parse(&p->zero, "0", 10, 0);
+ s = bc_num_parse(&p->last, "0", 10, 0);
if (s) goto zero_err;
- s = bc_num_parse(&p->one, "1", 10, 0);
+ s = bc_num_construct(&p->zero, BC_NUM_DEF_SIZE);
+
+ if (s) goto zero_err;
+
+ s = bc_num_parse(&p->zero, "0", 10, 0);
if (s) goto one_err;
+ s = bc_num_construct(&p->one, BC_NUM_DEF_SIZE);
+
+ if (s) goto one_err;
+
+ s = bc_num_parse(&p->one, "1", 10, 0);
+
+ if (s) goto num_buf_err;
+
p->num_buf = malloc(BC_PROGRAM_BUF_SIZE + 1);
if (!p->num_buf) {
@@ -610,11 +622,13 @@
return BC_STATUS_EXEC_INVALID_EXPR;
}
- //result.num = arb_str2fxdpnt(str);
+ status = bc_num_construct(&result.num, strlen(str));
- //if (!result.num) {
- // return BC_STATUS_EXEC_INVALID_EXPR;
- //}
+ if (status) return status;
+
+ status = bc_num_parse(&result.num, str, p->ibase, p->scale);
+
+ if (status) return status;
result.type = BC_NUM_CONSTANT;
@@ -688,8 +702,6 @@
}
return status;
-
- return BC_STATUS_SUCCESS;
}
void bc_program_printCode(BcProgram* p) {