From 395efb9c8a0a0160a7b95769e9484bae5548bbde Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sat, 17 Aug 2024 20:47:33 +0300 Subject: add analyzer and fix some reported issues --- src/actualize.c | 4 ++-- src/compiler.c | 13 ++++++++++--- src/debug.c | 2 ++ src/lower.c | 5 +++-- src/res.c | 3 +++ src/source.mk | 2 +- 6 files changed, 21 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/actualize.c b/src/actualize.c index ba5475e..aa5b398 100644 --- a/src/actualize.c +++ b/src/actualize.c @@ -2289,7 +2289,7 @@ static int actualize_dot(struct act_state *state, if (!def) { semantic_error(scope->fctx, node, - "no such type"); + "no such type"); return -1; } @@ -2305,7 +2305,7 @@ static int actualize_dot(struct act_state *state, char *tstr = type_str(type); semantic_error(scope->fctx, node, "%s does not have have member", - tstr); + tstr); free(tstr); return -1; } diff --git a/src/compiler.c b/src/compiler.c index 14a838a..c29f6c7 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -82,21 +82,28 @@ static int process(struct scope **parent, int public, const char *file) return -1; struct parser *p = create_parser(); - if (!p) + if (!p) { + free((void *)buf); return -1; + } + parse(p, file, buf); struct ast *tree = p->tree; bool failed = p->failed; destroy_parser(p); - if (failed) + if (failed) { + free((void*)buf); return -1; + } ast_dump_list(0, tree); struct scope *scope = create_scope(); - if (!scope) + if (!scope) { + free((void *)buf); return -1; + } if (public) scope_set_flags(scope, SCOPE_PUBLIC); diff --git a/src/debug.c b/src/debug.c index 32c74a2..f91accd 100644 --- a/src/debug.c +++ b/src/debug.c @@ -345,6 +345,8 @@ char *type_str(struct type *t) char *buf = NULL; size_t size = 0; /* hehe */ FILE *memstream = open_memstream(&buf, &size); + if (!memstream) + return NULL; _type_str(memstream, t); diff --git a/src/lower.c b/src/lower.c index a01dd40..4093cbf 100644 --- a/src/lower.c +++ b/src/lower.c @@ -279,13 +279,14 @@ static int lower_param(struct lower_state *s, struct ast *p, struct vec *fixups) assert(p->k == AST_VAR_DEF); assert(var_init(p) == NULL); - if (is_primitive(p->t) || p->t->k == TYPE_PTR || p->t->k == TYPE_CALLABLE) { + if (is_primitive(p->t) || p->t->k == TYPE_PTR || + p->t->k == TYPE_CALLABLE) { return lower_simple_param(s, p); } if (p->t->k != TYPE_STRUCT) { semantic_error(p->scope->fctx, p, - "illegal type"); + "illegal type"); return -1; } diff --git a/src/res.c b/src/res.c index 12d25ce..1d2b25b 100644 --- a/src/res.c +++ b/src/res.c @@ -26,6 +26,9 @@ static void res_expand(struct res *r) struct res *res_create() { struct res *r = malloc(sizeof(struct res)); + if (!r) + return NULL; + r->n = 0; /* arbitrary number */ r->max = 1024; diff --git a/src/source.mk b/src/source.mk index e6e5182..703e4a8 100644 --- a/src/source.mk +++ b/src/source.mk @@ -1,2 +1,2 @@ SRC_LOCAL != echo src/*.c -EK_SOURCES := $(EK_SOURCES) $(SRC_LOCAL) gen/gen_parser.c +EK_SOURCES := $(EK_SOURCES) $(SRC_LOCAL) -- cgit v1.3