aboutsummaryrefslogtreecommitdiff
path: root/tasm/src
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-08-18 01:15:01 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-08-18 01:15:01 +0300
commita44c59b6ab7b45bd52408bb67c17b6aa09aefeef (patch)
treea102a0d1738403d6176b9a4b266e9fbb4c5d5ef1 /tasm/src
parent4f0647740a3353781eab29a34ab1e0c16a0551ca (diff)
downloadtri-a44c59b6ab7b45bd52408bb67c17b6aa09aefeef.tar.gz
tri-a44c59b6ab7b45bd52408bb67c17b6aa09aefeef.zip
enable analyzer for tasm, fix some reported issues
Diffstat (limited to 'tasm/src')
-rw-r--r--tasm/src/assembler.c30
-rw-r--r--tasm/src/source.mk8
2 files changed, 28 insertions, 10 deletions
diff --git a/tasm/src/assembler.c b/tasm/src/assembler.c
index d8b3ee6..690d9df 100644
--- a/tasm/src/assembler.c
+++ b/tasm/src/assembler.c
@@ -274,9 +274,21 @@ static int process(struct asm_ctx *ctx, const char *file)
int process_file(struct asm_ctx *ctx, const char *file)
{
const char *base = tasm_basename(file);
+ if (!base)
+ return -1;
+
const char *dir = tasm_dirname(file);
+ if (!dir) {
+ free((void *)base);
+ return -1;
+ }
const char *cwd = tasm_cwdname();
+ if (!cwd) {
+ free((void *)base);
+ free((void *)dir);
+ return -1;
+ }
chdir(dir);
int res = process(ctx, base);
@@ -292,6 +304,9 @@ int process_file(struct asm_ctx *ctx, const char *file)
static struct asm_ctx *asm_ctx_create()
{
struct asm_ctx *ctx = malloc(sizeof(struct asm_ctx));
+ if (!ctx)
+ return NULL;
+
/* code buffer */
ctx->size = 1;
ctx->buf = malloc(sizeof(tri_t));
@@ -482,17 +497,26 @@ int assemble(const char *outfile, const char *infile)
{
/** @todo cleanup */
struct asm_ctx *ctx = asm_ctx_create();
+ if (!ctx)
+ return -1;
+
int ret = process_file(ctx, infile);
- if (ret)
+ if (ret) {
+ asm_ctx_destroy(ctx);
return ret;
+ }
ret = fix_relocs(ctx);
- if (ret)
+ if (ret) {
+ asm_ctx_destroy(ctx);
return ret;
+ }
FILE *f = fopen(outfile, "wb");
- if (!f)
+ if (!f) {
+ asm_ctx_destroy(ctx);
return -1;
+ }
for (size_t i = 0; i < ctx->idx; ++i) {
tri_t t = ctx->buf[i];
diff --git a/tasm/src/source.mk b/tasm/src/source.mk
index 5052ba3..a82d9f3 100644
--- a/tasm/src/source.mk
+++ b/tasm/src/source.mk
@@ -1,8 +1,2 @@
SOURCES != echo src/*.c
-TASM_SOURCES += $(SOURCES) gen/gen_parser.c
-
-gen/gen_parser.c: src/parser.y gen/gen_lexer.inc
- bison -Wcounterexamples -o gen/gen_parser.c src/parser.y
-
-gen/gen_lexer.inc: src/lexer.l
- flex -o gen/gen_lexer.inc src/lexer.l
+TASM_SOURCES += $(SOURCES)