aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-08-17 20:47:33 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-08-17 20:47:33 +0300
commit395efb9c8a0a0160a7b95769e9484bae5548bbde (patch)
treea5b4dc24dd3a2097d055b66b0cde8e23832802eb /src
parent2023a7b2d9656f80b00de81453348c0a66f200f7 (diff)
downloadek-395efb9c8a0a0160a7b95769e9484bae5548bbde.tar.gz
ek-395efb9c8a0a0160a7b95769e9484bae5548bbde.zip
add analyzer and fix some reported issues
Diffstat (limited to 'src')
-rw-r--r--src/actualize.c4
-rw-r--r--src/compiler.c13
-rw-r--r--src/debug.c2
-rw-r--r--src/lower.c5
-rw-r--r--src/res.c3
-rw-r--r--src/source.mk2
6 files changed, 21 insertions, 8 deletions
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)