chore: fixed all -Wextra warnings
authorLukas Krickl <lukas@krickl.dev>
Mon, 23 Mar 2026 04:48:33 +0000 (05:48 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 23 Mar 2026 04:48:33 +0000 (05:48 +0100)
Enabled -Werror

README.md
makefile
src/main.c
src/test.c
src/ulas.c
src/uldas.c

index 9cfffe012ca4c83f9922064f0d3710c32e1a8e94..4e03e7b5d33048649ccf5f2243ee45a5ee85b318 100644 (file)
--- 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
 
index c41b6f238cb7b3c0a54518b9d8796597798834dd..4fd7a4e0d98c9a9e75e6652539806f870b5486cb 100644 (file)
--- 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)
 
index 66f8b5a58770e4654b16e887c4d52f6f1cd3df01..8c34bb24f4f6d72e43b31e8530957b8839c0cc03 100644 (file)
@@ -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]);
   }
 
index 60979735285fc69f794551cdcb75f00fa7f635b1..6b86dd07b425c1bc859758fdcd15e0a10b3cc9eb 100644 (file)
@@ -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':
index b6c133aa58329377d1e178c02c9d4fd972371d4a..bbb51df3bdf78940391710d957b546082196f1c6 100644 (file)
@@ -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
index 87a39492fb905fc7d377abd8491be818ed7e363a..ff6ce890b1cae727ec4ae49b121737a2d2db53ee 100644 (file)
@@ -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;