shithub: rgbds

Download patch

ref: ac59ecf3c0906312aa0aa8c064e6130bb2caf318
parent: 72b677a8d7d5f334b67b5a9bfadf98261fdd43cc
author: ISSOtm <eldredhabert0@gmail.com>
date: Sat Feb 5 09:19:25 EST 2022

Enable `-Wsign-compare` and fix the warnings

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -54,7 +54,6 @@
                         -Wold-style-definition -Wshift-overflow=2 -Wstrict-overflow=5
                         -Wstrict-prototypes -Wstringop-overflow=4 -Wundef -Wuninitialized -Wunused
                         -Wshadow # TODO: -Wshadow=compatible-local ?
-                        -Wno-sign-compare # TODO: fix those warnings
                         -Wformat=2 -Wformat-overflow=2 -Wformat-truncation=1
                         -Wno-format-nonliteral # We have a couple of "dynamic" prints
                         # We do some range checks that are always false on some platforms (GCC, Clang)
--- a/Makefile
+++ b/Makefile
@@ -219,7 +219,6 @@
 		-Wstrict-overflow=5 -Wstrict-prototypes -Wundef -Wuninitialized -Wunused \
 		-Wshadow \
 		-Wnull-dereference -Wstringop-overflow=4 \
-		-Wno-sign-compare \
 		-Wformat=2 -Wformat-overflow=2 -Wformat-truncation=1 \
 		-Wno-format-nonliteral \
 		-Wno-type-limits -Wno-tautological-constant-out-of-range-compare \
--- a/include/gfx/main.h
+++ b/include/gfx/main.h
@@ -24,7 +24,7 @@
 	bool mirror;
 	bool unique;
 	bool colorcurve;
-	int trim;
+	unsigned int trim;
 	char *tilemapfile;
 	bool tilemapout;
 	char *attrmapfile;
@@ -43,7 +43,7 @@
 
 struct ImageOptions {
 	bool horizontal;
-	int trim;
+	unsigned int trim;
 	char *tilemapfile;
 	bool tilemapout;
 	char *attrmapfile;
--- a/src/asm/output.c
+++ b/src/asm/output.c
@@ -192,7 +192,7 @@
 
 static uint32_t getSectIDIfAny(struct Section const *sect)
 {
-	return sect ? getsectid(sect) : -1;
+	return sect ? getsectid(sect) : (uint32_t)-1;
 }
 
 /*
@@ -200,7 +200,7 @@
  */
 static void writepatch(struct Patch const *patch, FILE *f)
 {
-	assert(patch->src->ID != -1);
+	assert(patch->src->ID != (uint32_t)-1);
 	putlong(patch->src->ID, f);
 	putlong(patch->lineNo, f);
 	putlong(patch->offset, f);
@@ -264,7 +264,7 @@
 	if (!sym_IsDefined(sym)) {
 		putc(SYMTYPE_IMPORT, f);
 	} else {
-		assert(sym->src->ID != -1);
+		assert(sym->src->ID != (uint32_t)-1);
 
 		putc(sym->isExported ? SYMTYPE_EXPORT : SYMTYPE_LOCAL, f);
 		putlong(sym->src->ID, f);
@@ -490,7 +490,7 @@
 
 static void writeFileStackNode(struct FileStackNode const *node, FILE *f)
 {
-	putlong(node->parent ? node->parent->ID : -1, f);
+	putlong(node->parent ? node->parent->ID : (uint32_t)-1, f);
 	putlong(node->lineNo, f);
 	putc(node->type, f);
 	if (node->type != NODE_REPT) {
--- a/src/gfx/gb.c
+++ b/src/gfx/gb.c
@@ -37,15 +37,14 @@
 
 void raw_to_gb(const struct RawIndexedImage *raw_image, struct GBImage *gb)
 {
-	int x, y, byte;
 	uint8_t index;
 
-	for (y = 0; y < raw_image->height; y++) {
-		for (x = 0; x < raw_image->width; x++) {
+	for (unsigned int y = 0; y < raw_image->height; y++) {
+		for (unsigned int x = 0; x < raw_image->width; x++) {
 			index = raw_image->data[y][x];
 			index &= (1 << depth) - 1;
 
-			byte = y * depth
+			unsigned int byte = y * depth
 				+ x / 8 * raw_image->height / 8 * 8 * depth;
 			gb->data[byte] |= (index & 1) << (7 - x % 8);
 			if (depth == 2) {
--- a/src/gfx/makepng.c
+++ b/src/gfx/makepng.c
@@ -142,10 +142,9 @@
 
 void destroy_raw_image(struct RawIndexedImage **raw_image_ptr_ptr)
 {
-	int y;
 	struct RawIndexedImage *raw_image = *raw_image_ptr_ptr;
 
-	for (y = 0; y < raw_image->height; y++)
+	for (unsigned int y = 0; y < raw_image->height; y++)
 		free(raw_image->data[y]);
 
 	free(raw_image->data);
--- a/src/link/patch.c
+++ b/src/link/patch.c
@@ -111,7 +111,7 @@
 static struct Symbol const *getSymbol(struct Symbol const * const *symbolList,
 				      uint32_t index)
 {
-	assert(index != -1); /* PC needs to be handled specially, not here */
+	assert(index != (uint32_t)-1); /* PC needs to be handled specially, not here */
 	struct Symbol const *symbol = symbolList[index];
 
 	/* If the symbol is defined elsewhere... */