From efccf6c931b2482a738b6372e6285932d8ccbac0 Mon Sep 17 00:00:00 2001 From: Rangi Date: Wed, 17 Nov 2021 23:51:40 -0500 Subject: [PATCH] A few stylistic tweaks - `goto free_romx` -> the more typical `goto cleanup` - `goto fail` -> the more typical `goto finish` - Remove a redundant `todo` variable --- src/asm/lexer.c | 4 ++-- src/asm/section.c | 6 ++---- src/fix/main.c | 21 ++++++++++----------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/asm/lexer.c b/src/asm/lexer.c index 9a36a4dd..9475d7e3 100644 --- a/src/asm/lexer.c +++ b/src/asm/lexer.c @@ -2257,8 +2257,8 @@ static int skipIfBlock(bool toEndc) } } while (!atLineStart); } -finish: +finish: lexerState->disableMacroArgs = false; lexerState->disableInterpolation = false; lexerState->atLineStart = false; @@ -2344,8 +2344,8 @@ static int yylex_SKIP_TO_ENDR(void) } } while (!atLineStart); } -finish: +finish: lexerState->disableMacroArgs = false; lexerState->disableInterpolation = false; lexerState->atLineStart = false; diff --git a/src/asm/section.c b/src/asm/section.c index f268df7a..8094301a 100644 --- a/src/asm/section.c +++ b/src/asm/section.c @@ -951,9 +951,7 @@ void sect_BinaryFileSlice(char const *s, int32_t start_pos, int32_t length) (void)fgetc(f); } - int32_t todo = length; - - while (todo--) { + while (length--) { int byte = fgetc(f); if (byte != EOF) { @@ -962,7 +960,7 @@ void sect_BinaryFileSlice(char const *s, int32_t start_pos, int32_t length) error("Error reading INCBIN file '%s': %s\n", s, strerror(errno)); } else { error("Premature end of file (%" PRId32 " bytes left to read)\n", - todo + 1); + length + 1); } } diff --git a/src/fix/main.c b/src/fix/main.c index b323dd3d..8e744216 100644 --- a/src/fix/main.c +++ b/src/fix/main.c @@ -1016,8 +1016,7 @@ static void processFile(int input, int output, char const *name, off_t fileSize) static_assert(0x10000 * BANK_SIZE <= SSIZE_MAX, "Max input file size too large for OS"); if (nbBanks == 0x10000) { report("FATAL: \"%s\" has more than 65536 banks\n", name); - free(romx); - return; + goto cleanup; } nbBanks++; @@ -1106,7 +1105,7 @@ static void processFile(int input, int output, char const *name, off_t fileSize) if (input == output) { if (lseek(output, 0, SEEK_SET) == (off_t)-1) { report("FATAL: Failed to rewind \"%s\": %s\n", name, strerror(errno)); - goto free_romx; + goto cleanup; } // If modifying the file in-place, we only need to edit the header // However, padding may have modified ROM0 (added padding), so don't in that case @@ -1117,11 +1116,11 @@ static void processFile(int input, int output, char const *name, off_t fileSize) if (writeLen == -1) { report("FATAL: Failed to write \"%s\"'s ROM0: %s\n", name, strerror(errno)); - goto free_romx; + goto cleanup; } else if (writeLen < rom0Len) { report("FATAL: Could only write %jd of \"%s\"'s %jd ROM0 bytes\n", (intmax_t)writeLen, name, (intmax_t)rom0Len); - goto free_romx; + goto cleanup; } // Output ROMX if it was buffered @@ -1131,11 +1130,11 @@ static void processFile(int input, int output, char const *name, off_t fileSize) writeLen = writeBytes(output, romx, totalRomxLen); if (writeLen == -1) { report("FATAL: Failed to write \"%s\"'s ROMX: %s\n", name, strerror(errno)); - goto free_romx; + goto cleanup; } else if ((size_t)writeLen < totalRomxLen) { report("FATAL: Could only write %jd of \"%s\"'s %zu ROMX bytes\n", (intmax_t)writeLen, name, totalRomxLen); - goto free_romx; + goto cleanup; } } @@ -1145,7 +1144,7 @@ static void processFile(int input, int output, char const *name, off_t fileSize) if (lseek(output, 0, SEEK_END) == (off_t)-1) { report("FATAL: Failed to seek to end of \"%s\": %s\n", name, strerror(errno)); - goto free_romx; + goto cleanup; } } memset(bank, padValue, sizeof(bank)); @@ -1167,7 +1166,7 @@ static void processFile(int input, int output, char const *name, off_t fileSize) } } -free_romx: +cleanup: free(romx); } @@ -1192,7 +1191,7 @@ static bool processFilename(char const *name) if (input == -1) { report("FATAL: Failed to open \"%s\" for reading+writing: %s\n", name, strerror(errno)); - goto fail; + goto finish; } if (fstat(input, &stat) == -1) { @@ -1211,8 +1210,8 @@ static bool processFilename(char const *name) close(input); } +finish: if (nbErrors) -fail: fprintf(stderr, "Fixing \"%s\" failed with %u error%s\n", name, nbErrors, nbErrors == 1 ? "" : "s"); return nbErrors;