fix: sanitizer checks fix (iteration 1)
This commit is contained in:
+119
-73
@@ -9,6 +9,16 @@
|
||||
char plast_err[256];
|
||||
fzl_token_t *last_known_tok = NULL;
|
||||
|
||||
fzl_token_t null_tok = {
|
||||
.type = FZL_TOKTYPE_TYPE,
|
||||
.filename = "",
|
||||
.ln = 0,
|
||||
.cn = 0,
|
||||
.store_value = true,
|
||||
.value = "null",
|
||||
.value_sz = 4,
|
||||
};
|
||||
|
||||
fzl_parser_t *fzl_mkparser(fzl_reader_ll_t *first)
|
||||
{
|
||||
if (!first)
|
||||
@@ -35,6 +45,7 @@ fzl_parser_t *fzl_mkparser(fzl_reader_ll_t *first)
|
||||
fzl_node_t *fzl_mknode(fzl_nodetype_t type, fzl_token_t *token)
|
||||
{
|
||||
fzl_node_t *node = malloc(sizeof(fzl_node_t));
|
||||
memset(node, 0, sizeof(fzl_node_t));
|
||||
|
||||
if (!node)
|
||||
return NULL;
|
||||
@@ -226,7 +237,7 @@ fzl_node_t *parse_postfix(fzl_parser_t *parser)
|
||||
if (args_capacity <= args_count)
|
||||
{
|
||||
args_capacity *= 2;
|
||||
args = realloc(args, args_capacity * sizeof(fzl_node_t));
|
||||
args = realloc(args, args_capacity * sizeof(fzl_node_t *));
|
||||
}
|
||||
|
||||
args[args_count] = arg;
|
||||
@@ -700,9 +711,19 @@ fzl_node_t *parse_class(fzl_parser_t *parser)
|
||||
}
|
||||
}
|
||||
|
||||
fzl_node_t **new_args = realloc(node->fn.args, ++node->fn.args_count);
|
||||
memcpy(&new_args[1], new_args,
|
||||
(node->fn.args_count - 1) * sizeof(fzl_node_t *));
|
||||
fzl_node_t **new_args = realloc(node->fn.args, (++node->fn.args_count) *
|
||||
sizeof(fzl_node_t *));
|
||||
if (!new_args)
|
||||
{
|
||||
snprintf(plast_err, sizeof(plast_err),
|
||||
"failed to reallocate method args list");
|
||||
free(fields);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (node->fn.args_count > 1)
|
||||
memmove(&new_args[1], new_args,
|
||||
(node->fn.args_count - 1) * sizeof(fzl_node_t *));
|
||||
|
||||
fzl_token_t *this_tok =
|
||||
fzl_mktoken(FZL_TOKTYPE_NAME, node->fn.name->ln, node->fn.name->cn,
|
||||
@@ -713,6 +734,7 @@ fzl_node_t *parse_class(fzl_parser_t *parser)
|
||||
this_dec->var.identifier = this_id;
|
||||
|
||||
new_args[0] = this_dec;
|
||||
node->fn.args = new_args;
|
||||
methods[mcount++] = node;
|
||||
}
|
||||
else
|
||||
@@ -814,8 +836,7 @@ fzl_node_t *parse_function(fzl_parser_t *parser)
|
||||
type = consume(parser);
|
||||
|
||||
if (!type)
|
||||
type = fzl_mktoken(FZL_TOKTYPE_TYPE, last_known_tok->ln, last_known_tok->cn,
|
||||
"null", 4, last_known_tok->filename);
|
||||
type = &null_tok;
|
||||
|
||||
if (!is(parser, FZL_TOKTYPE_LBRACE))
|
||||
{
|
||||
@@ -1051,80 +1072,105 @@ void fzl_freeast(fzl_node_t *root)
|
||||
|
||||
while (root)
|
||||
{
|
||||
if (root->type == FZL_NODETYPE_BLOCK)
|
||||
switch (root->type)
|
||||
{
|
||||
if (root->list.entries)
|
||||
{
|
||||
for (size_t i = 0; i < root->list.entry_count; i++)
|
||||
if (root->list.entries[i])
|
||||
fzl_freeast(root->list.entries[i]);
|
||||
case FZL_NODETYPE_IDENTIFIER:
|
||||
case FZL_NODETYPE_LITERAL:
|
||||
break;
|
||||
|
||||
free(root->list.entries);
|
||||
}
|
||||
}
|
||||
else if (root->type == FZL_NODETYPE_CALL)
|
||||
{
|
||||
if (root->call.args_count)
|
||||
{
|
||||
for (size_t i = 0; i < root->call.args_count; i++)
|
||||
if (root->call.args[i])
|
||||
fzl_freeast(root->call.args[i]);
|
||||
case FZL_NODETYPE_BLOCK:
|
||||
if (root->list.entries)
|
||||
{
|
||||
for (size_t i = 0; i < root->list.entry_count; i++)
|
||||
if (root->list.entries[i])
|
||||
fzl_freeast(root->list.entries[i]);
|
||||
|
||||
free(root->call.args);
|
||||
}
|
||||
}
|
||||
else if (root->type == FZL_NODETYPE_ADD || root->type == FZL_NODETYPE_SUB ||
|
||||
root->type == FZL_NODETYPE_MUL || root->type == FZL_NODETYPE_DIV ||
|
||||
root->type == FZL_NODETYPE_POW || root->type == FZL_NODETYPE_MOD)
|
||||
{
|
||||
if (root->binary_op.left)
|
||||
fzl_freeast(root->binary_op.left);
|
||||
if (root->binary_op.right)
|
||||
fzl_freeast(root->binary_op.right);
|
||||
}
|
||||
else if (root->type == FZL_NODETYPE_UNARY_PLUS ||
|
||||
root->type == FZL_NODETYPE_UNARY_MINUS)
|
||||
{
|
||||
if (root->unary_op.operand)
|
||||
fzl_freeast(root->unary_op.operand);
|
||||
}
|
||||
else if (root->type == FZL_NODETYPE_FUNCTION)
|
||||
{
|
||||
if (root->fn.args_count)
|
||||
for (size_t i = 0; i < root->fn.args_count; i++)
|
||||
fzl_freenode(root->fn.args[i]);
|
||||
free(root->fn.args);
|
||||
fzl_freenode(root->fn.body);
|
||||
}
|
||||
else if (root->type == FZL_NODETYPE_RETURN)
|
||||
{
|
||||
if (root->ret.value)
|
||||
fzl_freenode(root->ret.value);
|
||||
}
|
||||
else if (root->type == FZL_NODETYPE_CLASS)
|
||||
{
|
||||
if (root->class.fields_count)
|
||||
for (size_t i = 0; i < root->class.fields_count; i++)
|
||||
fzl_freenode(root->class.fields[i]);
|
||||
free(root->class.fields);
|
||||
free(root->list.entries);
|
||||
}
|
||||
break;
|
||||
|
||||
if (root->class.methods_count)
|
||||
for (size_t i = 0; i < root->class.methods_count; i++)
|
||||
fzl_freenode(root->class.methods[i]);
|
||||
free(root->class.methods);
|
||||
}
|
||||
else if (root->type == FZL_NODETYPE_CONSTRUCT)
|
||||
{
|
||||
fzl_freenode(root->construct.name);
|
||||
}
|
||||
else if (root->type == FZL_NODETYPE_FIELD)
|
||||
{
|
||||
fzl_freenode(root->memb.field);
|
||||
fzl_freenode(root->memb.parent);
|
||||
case FZL_NODETYPE_CALL:
|
||||
if (root->call.args_count)
|
||||
{
|
||||
for (size_t i = 0; i < root->call.args_count; i++)
|
||||
if (root->call.args[i])
|
||||
fzl_freeast(root->call.args[i]);
|
||||
|
||||
free(root->call.args);
|
||||
}
|
||||
break;
|
||||
|
||||
case FZL_NODETYPE_ADD:
|
||||
case FZL_NODETYPE_SUB:
|
||||
case FZL_NODETYPE_MUL:
|
||||
case FZL_NODETYPE_DIV:
|
||||
case FZL_NODETYPE_POW:
|
||||
case FZL_NODETYPE_MOD:
|
||||
case FZL_NODETYPE_CONDITIONAL:
|
||||
case FZL_NODETYPE_OR:
|
||||
case FZL_NODETYPE_AND:
|
||||
case FZL_NODETYPE_EQUAL:
|
||||
case FZL_NODETYPE_NEQUAL:
|
||||
case FZL_NODETYPE_LESS:
|
||||
case FZL_NODETYPE_LESS_EQUAL:
|
||||
case FZL_NODETYPE_GREATER:
|
||||
case FZL_NODETYPE_GREATER_EQUAL:
|
||||
case FZL_NODETYPE_ASSIGN:
|
||||
if (root->binary_op.left)
|
||||
fzl_freeast(root->binary_op.left);
|
||||
if (root->binary_op.right)
|
||||
fzl_freeast(root->binary_op.right);
|
||||
break;
|
||||
|
||||
case FZL_NODETYPE_UNARY_PLUS:
|
||||
case FZL_NODETYPE_UNARY_MINUS:
|
||||
case FZL_NODETYPE_NOT:
|
||||
if (root->unary_op.operand)
|
||||
fzl_freeast(root->unary_op.operand);
|
||||
break;
|
||||
|
||||
case FZL_NODETYPE_FUNCTION:
|
||||
if (root->fn.args_count)
|
||||
for (size_t i = 0; i < root->fn.args_count; i++)
|
||||
fzl_freeast(root->fn.args[i]);
|
||||
free(root->fn.args);
|
||||
fzl_freeast(root->fn.body);
|
||||
break;
|
||||
|
||||
case FZL_NODETYPE_RETURN:
|
||||
if (root->ret.value)
|
||||
fzl_freeast(root->ret.value);
|
||||
break;
|
||||
|
||||
case FZL_NODETYPE_CLASS:
|
||||
if (root->class.fields_count)
|
||||
for (size_t i = 0; i < root->class.fields_count; i++)
|
||||
fzl_freeast(root->class.fields[i]);
|
||||
free(root->class.fields);
|
||||
|
||||
if (root->class.methods_count)
|
||||
for (size_t i = 0; i < root->class.methods_count; i++)
|
||||
fzl_freeast(root->class.methods[i]);
|
||||
free(root->class.methods);
|
||||
break;
|
||||
|
||||
case FZL_NODETYPE_CONSTRUCT:
|
||||
fzl_freeast(root->construct.name);
|
||||
break;
|
||||
|
||||
case FZL_NODETYPE_FIELD:
|
||||
fzl_freeast(root->memb.field);
|
||||
fzl_freeast(root->memb.parent);
|
||||
break;
|
||||
|
||||
case FZL_NODETYPE_DECLARATION:
|
||||
if (root->var.identifier)
|
||||
fzl_freeast(root->var.identifier);
|
||||
break;
|
||||
}
|
||||
|
||||
fzl_node_t *next = root->next;
|
||||
free(root);
|
||||
fzl_freenode(root);
|
||||
root = next;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user