diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-08-18 01:15:01 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-08-18 01:15:01 +0300 |
| commit | a44c59b6ab7b45bd52408bb67c17b6aa09aefeef (patch) | |
| tree | a102a0d1738403d6176b9a4b266e9fbb4c5d5ef1 /tasm/src/assembler.c | |
| parent | 4f0647740a3353781eab29a34ab1e0c16a0551ca (diff) | |
| download | tri-a44c59b6ab7b45bd52408bb67c17b6aa09aefeef.tar.gz tri-a44c59b6ab7b45bd52408bb67c17b6aa09aefeef.zip | |
enable analyzer for tasm, fix some reported issues
Diffstat (limited to 'tasm/src/assembler.c')
| -rw-r--r-- | tasm/src/assembler.c | 30 |
1 files changed, 27 insertions, 3 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]; |
