make put all frees after set_err
I had the case that frees would invalidate memory set_err would later use, so putting frees after set_err is probably good practice.
This commit is contained in:
parent
f6b74f8f97
commit
e7da8dfe38
1
lex.c
1
lex.c
@ -339,6 +339,7 @@ TokList lex(const char *s) {
|
|||||||
c = get_esc_char(s[0]);
|
c = get_esc_char(s[0]);
|
||||||
if (!c) {
|
if (!c) {
|
||||||
set_err("Unrecognized escape sequence: '\\%c'", c);
|
set_err("Unrecognized escape sequence: '\\%c'", c);
|
||||||
|
free(str);
|
||||||
return toks;
|
return toks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
parse.c
4
parse.c
@ -454,9 +454,9 @@ static ExprRet expr(IRList *out_ir, TokList *toks, Map *funcs, Scope *parent_sc,
|
|||||||
for (size_t i = 0; i < elems_len; i++) {
|
for (size_t i = 0; i < elems_len; i++) {
|
||||||
Value *v = &elems[i].Literal;
|
Value *v = &elems[i].Literal;
|
||||||
if (v->type != arr_ty) {
|
if (v->type != arr_ty) {
|
||||||
|
set_err("Type of array item %zu (%s) differs from array type (%s)", i, type_str[v->type], type_str[arr_ty]);
|
||||||
free(arr_vals);
|
free(arr_vals);
|
||||||
free(elems);
|
free(elems);
|
||||||
set_err("Type of array item %zu (%s) differs from array type (%s)", i, type_str[v->type], type_str[arr_ty]);
|
|
||||||
return (ExprRet){0};
|
return (ExprRet){0};
|
||||||
}
|
}
|
||||||
memcpy((uint8_t*)arr_vals + type_size[arr_ty] * i, &v->Void, type_size[arr_ty]);
|
memcpy((uint8_t*)arr_vals + type_size[arr_ty] * i, &v->Void, type_size[arr_ty]);
|
||||||
@ -729,9 +729,9 @@ static void stmt(IRList *out_ir, TokList *toks, Map *funcs, Scope *sc, TokListIt
|
|||||||
skip_newlns(toks, t->next);
|
skip_newlns(toks, t->next);
|
||||||
if (t->next->tok.kind == TokOp) {
|
if (t->next->tok.kind == TokOp) {
|
||||||
if (t->next->tok.Op == OpEOF) {
|
if (t->next->tok.Op == OpEOF) {
|
||||||
term_scope(&inner_sc);
|
|
||||||
mark_err(&start->tok);
|
mark_err(&start->tok);
|
||||||
set_err("Unclosed '{'");
|
set_err("Unclosed '{'");
|
||||||
|
term_scope(&inner_sc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (t->next->tok.Op == OpRCurl)
|
if (t->next->tok.Op == OpRCurl)
|
||||||
|
4
vm.c
4
vm.c
@ -92,9 +92,9 @@ void run(IRList *ir, const BuiltinFunc *builtin_funcs) {
|
|||||||
}
|
}
|
||||||
case IRAddrOf: {
|
case IRAddrOf: {
|
||||||
if (instr->Unary.val.kind != IRParamAddr) {
|
if (instr->Unary.val.kind != IRParamAddr) {
|
||||||
|
set_err("Unable to take the address of a literal");
|
||||||
free(fn_args);
|
free(fn_args);
|
||||||
stack_term(&s);
|
stack_term(&s);
|
||||||
set_err("Unable to take the address of a literal");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Value *v = &s.mem[instr->Unary.val.Addr];
|
Value *v = &s.mem[instr->Unary.val.Addr];
|
||||||
@ -195,10 +195,10 @@ void run(IRList *ir, const BuiltinFunc *builtin_funcs) {
|
|||||||
for (size_t j = 0; j < arr_len; j++) {
|
for (size_t j = 0; j < arr_len; j++) {
|
||||||
Value *v = irparam_to_val(&s, &instr->ArrMake.vals[j]);
|
Value *v = irparam_to_val(&s, &instr->ArrMake.vals[j]);
|
||||||
if (v->type != arr_ty) {
|
if (v->type != arr_ty) {
|
||||||
|
set_err("Type of array item %zu (%s) differs from array type (%s)", j, type_str[v->type], type_str[arr_ty]);
|
||||||
free(arr_vals);
|
free(arr_vals);
|
||||||
free(fn_args);
|
free(fn_args);
|
||||||
stack_term(&s);
|
stack_term(&s);
|
||||||
set_err("Type of array item %zu (%s) differs from array type (%s)", j, type_str[v->type], type_str[arr_ty]);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
memcpy((uint8_t*)arr_vals + type_size[arr_ty] * j, &v->Void, type_size[arr_ty]);
|
memcpy((uint8_t*)arr_vals + type_size[arr_ty] * j, &v->Void, type_size[arr_ty]);
|
||||||
|
Loading…
Reference in New Issue
Block a user