diff --git a/Makefile b/Makefile index 75f18e60..433b5988 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,12 @@ VERSION_STRING := `git describe --tags --dirty --always 2>/dev/null` 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 diff --git a/src/asm/lexer.c b/src/asm/lexer.c index fd0b3d17..20b6690a 100644 --- a/src/asm/lexer.c +++ b/src/asm/lexer.c @@ -414,7 +414,7 @@ void yylex_GetFloatMaskAndFloatLen(uint32_t *pnFloatMask, uint32_t *pnFloatLen) /* * 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; diff --git a/src/asm/main.c b/src/asm/main.c index 3996ff89..4be82181 100644 --- a/src/asm/main.c +++ b/src/asm/main.c @@ -6,6 +6,7 @@ * SPDX-License-Identifier: MIT */ +#include #include #include #include @@ -483,7 +484,7 @@ int main(int argc, char *argv[]) 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", diff --git a/src/gfx/makepng.c b/src/gfx/makepng.c index 88654afb..38f54d4c 100644 --- a/src/gfx/makepng.c +++ b/src/gfx/makepng.c @@ -469,8 +469,10 @@ struct ColorWithLuminance { 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; } diff --git a/src/link/assign.c b/src/link/assign.c index 73c644ae..e2c4b1ee 100644 --- a/src/link/assign.c +++ b/src/link/assign.c @@ -74,6 +74,10 @@ static void do_max_bank(enum eSectionType Type, int32_t nBank) 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 SetLinkerscriptName(char *tzLinkerscriptFile) void AssignSections(void) { - int32_t i; struct sSection *pSection; MaxBankUsed = 0; @@ -503,7 +506,7 @@ void AssignSections(void) * 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 @@ void AssignSections(void) 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; } diff --git a/src/link/lexer.l b/src/link/lexer.l index 156ddf0c..ac5a4fff 100644 --- 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. */ diff --git a/src/link/parser.y b/src/link/parser.y index a532f560..8e6a2094 100644 --- 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 @@ statement: %% -extern int yylex(); -extern int yyparse(); +extern int yylex(void); +extern int yyparse(void); int yywrap(void) { diff --git a/src/link/script.c b/src/link/script.c index 55e6c193..913b69ad 100644 --- a/src/link/script.c +++ b/src/link/script.c @@ -85,59 +85,59 @@ void script_InitSections(void) } } -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; 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 @@ void script_SetCurrentSectionType(const char *type, uint32_t bank) 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__); }