allow solve to error safely

master
Clyne 7 years ago
parent 2f3ffd1109
commit 7faeef296d

@ -133,8 +133,10 @@ int bn_solve(instance *it)
{ {
variable *s = igetarg(it, 0); variable *s = igetarg(it, 0);
variable **ops = iparse(it, (const char *)s->value.p); variable **ops = iparse(it, (const char *)s->value.p);
if (ops == 0) if (ops == 0) {
return -1; ipush(it, (uint32_t)make_varf(0, 0.0f));
return 0;
}
variable *a = isolve(it, ops, 0); variable *a = isolve(it, ops, 0);
free(ops); free(ops);

@ -290,12 +290,13 @@ int idoline(instance *it, const char *s)
return 0; return 0;
it->lines[it->lnidx] = ops; it->lines[it->lnidx] = ops;
variable **copy;
loop: loop:
if (it->ret != 0) //if (it->ret != 0)
itryfree(it->ret); // itryfree(it->ret);
it->ret = 0; //it->ret = 0;
variable **copy = (variable **)malloc(32 * sizeof(variable *)); copy = (variable **)malloc(32 * sizeof(variable *));
for (int i = 0; i < 32; i++) { for (int i = 0; i < 32; i++) {
variable *v = it->lines[it->lnidx][i]; variable *v = it->lines[it->lnidx][i];
if (v != 0) { if (v != 0) {
@ -317,8 +318,15 @@ loop:
} }
} }
it->ret = isolve(it, copy, 0); it->ret = isolve(it, copy, 0);
if (it->ret == 0) if (it->ret == 0) {
idelline(copy); idelline(copy);
} else {
variable *ret = igetvar(it, "ANS");
ret->type = it->ret->type;
ret->value.p = it->ret->value.p;
it->ret = ret;
}
free(copy); free(copy);
it->lnidx++; it->lnidx++;
@ -580,7 +588,12 @@ variable **iparse(instance *it, const char *s)
goto fail; goto fail;
} else { } else {
if (ooffset == 0) { if (ooffset == 0) {
ops[ooffset++] = make_varf(0, 0.0f); variable *a;
if (it->ret != 0)
a = it->ret;
else
a = make_varf(0, 0.0f);
ops[ooffset++] = a;
} else if (ops[ooffset - 1]->type == OPERATOR) { } else if (ops[ooffset - 1]->type == OPERATOR) {
free(word); free(word);
goto fail; goto fail;

Loading…
Cancel
Save