From e4638c4ef3f49efa89efac7edea69805b7b4c3f6 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Mon, 23 Mar 2026 05:48:33 +0100 Subject: [PATCH] chore: fixed all -Wextra warnings Enabled -Werror --- README.md | 2 +- makefile | 2 +- src/main.c | 2 +- src/test.c | 6 ++++-- src/ulas.c | 36 ++++++++++++++++++++++-------------- src/uldas.c | 5 +++-- 6 files changed, 32 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 9cfffe0..4e03e7b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ulas -Unlink's light assembler is a SM83 assembler without any external dependencies written in C99. +Unlink's light assembler is a SM83 assembler without any external dependencies written in C89. ## Table of content diff --git a/makefile b/makefile index c41b6f2..4fd7a4e 100644 --- a/makefile +++ b/makefile @@ -2,7 +2,7 @@ NAME=ulas TEST_NAME=test$(NAME) DBGCFLAGS=-g -fsanitize=address DBGLDFLAGS=-fsanitize=address -CFLAGS=-Wall -Wextra -pedantic $(DBGCFLAGS) -std=gnu89 +CFLAGS=-Wall -Wextra -Werror -pedantic $(DBGCFLAGS) -std=gnu89 LIBS= LDFLAGS=$(DBGLDFLAGS) $(LIBS) diff --git a/src/main.c b/src/main.c index 66f8b5a..8c34bb2 100644 --- a/src/main.c +++ b/src/main.c @@ -119,7 +119,7 @@ int main(int argc, char **argv) { free(cfg.lst_path); } - for (i = 0; i < incpathslen; i++) { + for (i = 0; i < (int)incpathslen; i++) { free(incpaths[i]); } diff --git a/src/test.c b/src/test.c index 6097973..6b86dd0 100644 --- a/src/test.c +++ b/src/test.c @@ -29,7 +29,7 @@ expect_n = 0; \ for (expect_n = 0; expect[expect_n]; expect_n++) { \ } \ - assert(i == expect_n); \ + assert(i == (int)expect_n); \ ulas_strfree(&dst); \ } @@ -49,7 +49,7 @@ expect_n = 0; \ for (expect_n = 0; expect[expect_n]; expect_n++) { \ } \ - assert(i == expect_n); \ + assert(i == (int)expect_n); \ ulas_strfree(&dst); \ } @@ -487,6 +487,8 @@ void test_help(void) { void test_getopt(int argc, char **argv, struct ulas_config *cfg) { int c = 0; + ULAS_UNUSED(cfg); + while ((c = getopt(argc, argv, ULAS_TEST_OPTS ULAS_TEST_OPTS_ARG)) != -1) { switch (c) { case 'h': diff --git a/src/ulas.c b/src/ulas.c index b6c133a..bbb51df 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -190,7 +190,7 @@ unsigned int ulas_strlcat(char *dst, const char *src, unsigned int max) { unsigned int src_len = ulas_strnlen(src, max); int i; - for (i = 0; i < src_len; i++) { + for (i = 0; i < (int)src_len; i++) { dst[dst_len+i] = src[i]; } @@ -207,7 +207,7 @@ FILE *ulas_incpathfopen(const char *path, const char *mode) { memset(pathbuf, 0, ULAS_PATHMAX); /* check all include paths */ - for (i = 0; i < ulascfg.incpathslen; i++) { + for (i = 0; i < (int)ulascfg.incpathslen; i++) { char *ip = ulascfg.incpaths[i]; unsigned long len = strlen(ip); pathbuf[0] = '\0'; @@ -405,7 +405,7 @@ int ulas_islabelname(const char *tok, unsigned long n) { struct ulas_sym *ulas_symbolresolve(const char *name, int scope, int *rc) { int i; - for (i = 0; i < ulas.syms.len; i++) { + for (i = 0; i < (int)ulas.syms.len; i++) { struct ulas_sym *sym = &ulas.syms.buf[i]; /* when scope is the same as the current one, or scope 0 (global) */ if ((sym->scope == 0 || sym->scope == scope) && @@ -462,7 +462,8 @@ int ulas_symbolset(const char *cname, int scope, struct ulas_tok tok, ulas_symbufpush(&ulas.syms, new_sym); rc = ulas_symbolout(ulassymout, &new_sym); - } else if (existing->lastdefin != ulas.pass || !existing->constant) { + } else if ((int)existing->lastdefin != (int)ulas.pass + || !existing->constant) { /* redefine if not defined this pass */ existing->lastdefin = ulas.pass; ulas_tokfree(&existing->tok); @@ -605,7 +606,7 @@ int ulas_symbolout(FILE *dst, struct ulas_sym *s) { } #define ULAS_TOKISTERM write -#define ULAS_TOKCOND (i < n && write < n && line[i]) +#define ULAS_TOKCOND (i < (int)n && write < (int)n && line[i]) #define ULAS_QUOTED_TOKEN(quote_char) { \ int last_escape = 0;\ dst->buf[write++] = line[i++];\ @@ -953,7 +954,7 @@ struct ulas_ppdef *ulas_preprocgetdef(struct ulas_preproc *pp, const char *name, int ulas_preproclws(struct ulas_preproc *pp, const char *praw_line, unsigned long maxlen) { int i = 0; - while (i < maxlen && praw_line[i] && isspace(praw_line[i])) { + while (i < (int)maxlen && praw_line[i] && isspace(praw_line[i])) { i++; } @@ -964,6 +965,7 @@ int ulas_preproclws(struct ulas_preproc *pp, const char *praw_line, void ulas_trimend(char c, char *buf, unsigned long n) { unsigned long buflen = ulas_strnlen(buf, n); + ULAS_UNUSED(c); if (buflen == 0) { return; } @@ -1549,7 +1551,7 @@ struct ulas_preproc ulas_preprocinit(void) { pp.macrobuf = ulas_str(8); /* set up initial defs */ - for (i = 0; i < ulascfg.defslen; i++) { + for (i = 0; i < (int)ulascfg.defslen; i++) { struct ulas_ppdef def; def.type = ULAS_PPDEF; def.name = ulas_strdup(ulascfg.defs[i]); @@ -1731,7 +1733,7 @@ struct ulas_exprbuf ulas_exprbuf(void) { } struct ulas_expr *ulas_exprbufget(struct ulas_exprbuf *eb, int i) { - if (i >= eb->len) { + if (i >= (int)eb->len) { return NULL; } @@ -1783,7 +1785,7 @@ int ulas_symbufpush(struct ulas_symbuf *sb, struct ulas_sym sym) { } struct ulas_sym *ulas_symbufget(struct ulas_symbuf *sb, int i) { - if (i >= sb->len) { + if (i >= (int)sb->len) { return NULL; } @@ -1792,7 +1794,7 @@ struct ulas_sym *ulas_symbufget(struct ulas_symbuf *sb, int i) { void ulas_symbufclear(struct ulas_symbuf *sb) { long i; - for (i = 0; i < sb->len; i++) { + for (i = 0; i < (int)sb->len; i++) { struct ulas_sym *s = &sb->buf[i]; free(s->name); } @@ -2444,7 +2446,7 @@ void ulas_asmlst(const char *line, const char *outbuf, unsigned long n) { fputs(" ", ulaslstout); outwrt = 0; - for (i = 0; i < n; i++) { + for (i = 0; i < (int)n; i++) { outwrt += fprintf(ulaslstout, "%02x ", outbuf[i] & 0xFF); } @@ -2464,7 +2466,7 @@ void ulas_asmout(FILE *dst, const char *outbuf, unsigned long n) { } if (ulas.address < 0x14C) { - for (i = 0; i < n; i++) { + for (i = 0; i < (int)n; i++) { ulas.chksm = (char)(ulas.chksm - outbuf[i] - 1); } } @@ -2686,7 +2688,7 @@ int ulas_asmdirstr(FILE *dst, const char **line, unsigned long n, int *rc) { len = strlen(s); /* apply char code map */ - for (i = 0; i < len; i++) { + for (i = 0; i < (int)len; i++) { s[i] = ulas.charcodemap[(int)s[i]]; } @@ -2728,6 +2730,7 @@ int ulas_asmdirincbin(FILE *dst, const char **line, unsigned long n, int *rc) { } int ulas_asmdiradv(FILE *dst, const char **line, unsigned long n, int *rc) { + ULAS_UNUSED(dst); ULAS_EVALEXPRS_BEGIN ulas.address += ulas_intexpr(line, ulas_strnlen(*line, n), rc); ULAS_EVALEXPRS_END @@ -2736,6 +2739,7 @@ int ulas_asmdiradv(FILE *dst, const char **line, unsigned long n, int *rc) { } int ulas_asmdirsetenum(FILE *dst, const char **line, unsigned long n, int *rc) { + ULAS_UNUSED(dst); ULAS_EVALEXPRS_BEGIN ulas.enumv = ulas_intexpr(line, ulas_strnlen(*line, n), rc); ULAS_EVALEXPRS_END @@ -2791,7 +2795,7 @@ int ulas_asmdirchr(FILE *dst, const char **line, unsigned long n, int *rc) { return 0; } - for (i = 0; i < len; i++, bit--) { + for (i = 0; i < (int)len; i++, bit--) { switch (ulas.tok.buf[i]) { case '0': /* 0 sets no bit */ @@ -2892,6 +2896,8 @@ int ulas_asmdirrep(FILE *dst, FILE *src, const char **line, unsigned long n) { int ulas_asmdirsection(FILE *dst, FILE *src, const char **line, unsigned long n) { + ULAS_UNUSED(dst); + ULAS_UNUSED(src); ulas_tok(&ulas.tok, line, n); if (!ulas_isname(ulas.tok.buf, MIN(strlen(ulas.tok.buf), ulas.tok.maxlen))) { ULASERR("Unexpected token '%s'\n", ulas.tok.buf); @@ -2904,6 +2910,8 @@ int ulas_asmdirsection(FILE *dst, FILE *src, const char **line, int ulas_asmdirbank(FILE *dst, FILE *src, const char **line, unsigned long n, int *rc) { + ULAS_UNUSED(dst); + ULAS_UNUSED(src); ULAS_EVALEXPRS_BEGIN ulas.bank = ulas_intexpr(line, ulas_strnlen(*line, n), rc); ULAS_EVALEXPRS_END diff --git a/src/uldas.c b/src/uldas.c index 87a3949..ff6ce89 100644 --- a/src/uldas.c +++ b/src/uldas.c @@ -75,6 +75,7 @@ void ulas_dasm_instr_fout(FILE *src, FILE *dst, const struct ulas_instr *instr, void ulas_dasm_db_fout(FILE *src, FILE *dst, const char *buf, unsigned long read) { ULAS_UNUSED(src); + ULAS_UNUSED(read); ulas.address++; if (ulas.pass != ULAS_PASS_FINAL) { return; @@ -102,7 +103,7 @@ int ulas_dasm_instr_check(FILE *src, FILE *dst, const struct ulas_instr *instr, /* do we even have enough data? * this is a general check for 1 byte */ - if (bi + 1 >= read) { + if (bi + 1 >= (int)read) { goto fail; } @@ -116,7 +117,7 @@ int ulas_dasm_instr_check(FILE *src, FILE *dst, const struct ulas_instr *instr, case ULAS_A16: /* need 2 bytes here */ bi += 2; - if (bi > read) { + if (bi > (int)read) { goto fail; } break; -- 2.30.2