shithub: rgbds

Download patch

ref: 340362d98468a8a52b4ddc5dd19a6281b79fa8f0
parent: 85ece882689527ad8f73cf05637dfca2b3fcb048
author: Antonio Niño Díaz <[email protected]>
date: Sat Mar 31 22:09:20 EDT 2018

Enable a few warning flags

Signed-off-by: Antonio Niño Díaz <[email protected]>

--- a/Makefile
+++ b/Makefile
@@ -28,7 +28,12 @@
 
 WARNFLAGS	:= -Werror -Wall -Wextra -Wpedantic -Wno-sign-compare -Wchkp \
 		   -Wformat=2 -Wformat-overflow=2 -Wformat-truncation=1 \
-		   -Wformat-y2k
+		   -Wformat-y2k -Wswitch-enum -Wunused -Wuninitialized \
+		   -Wunknown-pragmas -Wstrict-overflow=5 -Wstringop-overflow=4 \
+		   -Walloc-zero -Wduplicated-cond -Wfloat-equal -Wshadow \
+		   -Wcast-qual -Wcast-align -Wlogical-op -Wnested-externs \
+		   -Wno-aggressive-loop-optimizations -Winline \
+		   -Wstrict-prototypes -Wold-style-definition
 
 # Overridable CFLAGS
 CFLAGS		:= -g
--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -414,7 +414,7 @@
 /*
  * Gets the longest keyword/operator from the current position in the buffer.
  */
-struct sLexString *yylex_GetLongestFixed()
+struct sLexString *yylex_GetLongestFixed(void)
 {
 	struct sLexString *pLongestFixed = NULL;
 	char *s = pLexBuffer;
--- a/src/asm/main.c
+++ b/src/asm/main.c
@@ -6,6 +6,7 @@
  * SPDX-License-Identifier: MIT
  */
 
+#include <float.h>
 #include <math.h>
 #include <stdarg.h>
 #include <stdio.h>
@@ -483,7 +484,7 @@
 	if (CurrentOptions.verbose) {
 		printf("Success! %u lines in %d.%02d seconds ", nTotalLines,
 		       (int)timespent, ((int)(timespent * 100.0)) % 100);
-		if (timespent == 0)
+		if (timespent < FLT_MIN_EXP)
 			printf("(INFINITY lines/minute)\n");
 		else
 			printf("(%d lines/minute)\n",
--- a/src/gfx/makepng.c
+++ b/src/gfx/makepng.c
@@ -469,8 +469,10 @@
 
 static int compare_luminance(const void *a, const void *b)
 {
-	struct ColorWithLuminance *x = (struct ColorWithLuminance *)a;
-	struct ColorWithLuminance *y = (struct ColorWithLuminance *)b;
+	const struct ColorWithLuminance *x, *y;
+
+	x = (const struct ColorWithLuminance *)a;
+	y = (const struct ColorWithLuminance *)b;
 
 	return y->luminance - x->luminance;
 }
--- a/src/link/assign.c
+++ b/src/link/assign.c
@@ -74,6 +74,10 @@
 		if (nBank > MaxVBankUsed)
 			MaxVBankUsed = nBank;
 		break;
+	case SECT_ROM0:
+	case SECT_WRAM0:
+	case SECT_OAM:
+	case SECT_HRAM:
 	default:
 		break;
 	}
@@ -494,7 +498,6 @@
 
 void AssignSections(void)
 {
-	int32_t i;
 	struct sSection *pSection;
 
 	MaxBankUsed = 0;
@@ -503,7 +506,7 @@
 	 * Initialize the memory areas
 	 */
 
-	for (i = 0; i < BANK_INDEX_MAX; i += 1) {
+	for (int32_t i = 0; i < BANK_INDEX_MAX; i += 1) {
 		BankFree[i] = malloc(sizeof(*BankFree[i]));
 
 		if (!BankFree[i]) {
@@ -663,6 +666,10 @@
 			do_max_bank(pSection->Type, pSection->nBank);
 			break;
 
+		case SECT_ROM0:
+		case SECT_WRAM0:
+		case SECT_OAM:
+		case SECT_HRAM:
 		default: /* Handle other sections later */
 			break;
 		}
--- a/src/link/lexer.l
+++ b/src/link/lexer.l
@@ -23,7 +23,7 @@
 
 #include "types.h"
 
-extern int yyparse();
+extern int yyparse(void);
 
 /* File include stack. */
 
--- a/src/link/parser.y
+++ b/src/link/parser.y
@@ -14,7 +14,7 @@
 
 #include "link/script.h"
 
-int yylex();
+int yylex(void);
 void yyerror(char *);
 
 extern int yylineno;
@@ -107,8 +107,8 @@
 
 %%
 
-extern int yylex();
-extern int yyparse();
+extern int yylex(void);
+extern int yyparse(void);
 
 int yywrap(void)
 {
--- a/src/link/script.c
+++ b/src/link/script.c
@@ -85,34 +85,34 @@
 	}
 }
 
-void script_SetCurrentSectionType(const char *type, uint32_t bank)
+void script_SetCurrentSectionType(const char *type, uint32_t bank_num)
 {
 	if (strcmp(type, "ROM0") == 0) {
-		if (bank != 0)
+		if (bank_num != 0)
 			errx(1, "Trying to assign a bank number to ROM0.\n");
 		current_bank = BANK_INDEX_ROM0;
 		current_real_bank = 0;
 		return;
 	} else if (strcmp(type, "ROMX") == 0) {
-		if (bank == 0)
+		if (bank_num == 0)
 			errx(1, "ROMX index can't be 0.\n");
-		if (bank > BANK_COUNT_ROMX) {
-			errx(1, "ROMX index too big (%d > %d).\n", bank,
+		if (bank_num > BANK_COUNT_ROMX) {
+			errx(1, "ROMX index too big (%d > %d).\n", bank_num,
 			     BANK_COUNT_ROMX);
 		}
-		current_bank = BANK_INDEX_ROMX + bank - 1;
-		current_real_bank = bank;
+		current_bank = BANK_INDEX_ROMX + bank_num - 1;
+		current_real_bank = bank_num;
 		return;
 	} else if (strcmp(type, "VRAM") == 0) {
-		if (bank >= BANK_COUNT_VRAM) {
-			errx(1, "VRAM index too big (%d >= %d).\n", bank,
+		if (bank_num >= BANK_COUNT_VRAM) {
+			errx(1, "VRAM index too big (%d >= %d).\n", bank_num,
 			     BANK_COUNT_VRAM);
 		}
-		current_bank = BANK_INDEX_VRAM + bank;
-		current_real_bank = bank;
+		current_bank = BANK_INDEX_VRAM + bank_num;
+		current_real_bank = bank_num;
 		return;
 	} else if (strcmp(type, "WRAM0") == 0) {
-		if (bank != 0)
+		if (bank_num != 0)
 			errx(1, "Trying to assign a bank number to WRAM0.\n");
 
 		current_bank = BANK_INDEX_WRAM0;
@@ -119,25 +119,25 @@
 		current_real_bank = 0;
 		return;
 	} else if (strcmp(type, "WRAMX") == 0) {
-		if (bank == 0)
+		if (bank_num == 0)
 			errx(1, "WRAMX index can't be 0.\n");
-		if (bank > BANK_COUNT_WRAMX) {
-			errx(1, "WRAMX index too big (%d > %d).\n", bank,
+		if (bank_num > BANK_COUNT_WRAMX) {
+			errx(1, "WRAMX index too big (%d > %d).\n", bank_num,
 			     BANK_COUNT_WRAMX);
 		}
-		current_bank = BANK_INDEX_WRAMX + bank - 1;
-		current_real_bank = bank;
+		current_bank = BANK_INDEX_WRAMX + bank_num - 1;
+		current_real_bank = bank_num;
 		return;
 	} else if (strcmp(type, "SRAM") == 0) {
-		if (bank >= BANK_COUNT_SRAM) {
-			errx(1, "SRAM index too big (%d >= %d).\n", bank,
+		if (bank_num >= BANK_COUNT_SRAM) {
+			errx(1, "SRAM index too big (%d >= %d).\n", bank_num,
 			     BANK_COUNT_SRAM);
 		}
-		current_bank = BANK_INDEX_SRAM + bank;
-		current_real_bank = bank;
+		current_bank = BANK_INDEX_SRAM + bank_num;
+		current_real_bank = bank_num;
 		return;
 	} else if (strcmp(type, "OAM") == 0) {
-		if (bank != 0) {
+		if (bank_num != 0) {
 			errx(1, "%s: Trying to assign a bank number to OAM.\n",
 			     __func__);
 		}
@@ -145,7 +145,7 @@
 		current_real_bank = 0;
 		return;
 	} else if (strcmp(type, "HRAM") == 0) {
-		if (bank != 0) {
+		if (bank_num != 0) {
 			errx(1, "%s: Trying to assign a bank number to HRAM.\n",
 			     __func__);
 		}