shithub: rgbds

Download patch

ref: efccf6c931b2482a738b6372e6285932d8ccbac0
parent: e5552e27f2fc438eaf6582481ef696e09415f20d
author: Rangi <[email protected]>
date: Wed Nov 17 18:51:40 EST 2021

A few stylistic tweaks

- `goto free_romx` -> the more typical `goto cleanup`
- `goto fail` -> the more typical `goto finish`
- Remove a redundant `todo` variable

--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -2257,8 +2257,8 @@
 			}
 		} while (!atLineStart);
 	}
-finish:
 
+finish:
 	lexerState->disableMacroArgs = false;
 	lexerState->disableInterpolation = false;
 	lexerState->atLineStart = false;
@@ -2344,8 +2344,8 @@
 			}
 		} while (!atLineStart);
 	}
-finish:
 
+finish:
 	lexerState->disableMacroArgs = false;
 	lexerState->disableInterpolation = false;
 	lexerState->atLineStart = false;
--- a/src/asm/section.c
+++ b/src/asm/section.c
@@ -951,9 +951,7 @@
 			(void)fgetc(f);
 	}
 
-	int32_t todo = length;
-
-	while (todo--) {
+	while (length--) {
 		int byte = fgetc(f);
 
 		if (byte != EOF) {
@@ -962,7 +960,7 @@
 			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);
 		}
 	}
 
--- a/src/fix/main.c
+++ b/src/fix/main.c
@@ -1016,8 +1016,7 @@
 				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 @@
 	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 @@
 
 	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 @@
 		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 @@
 			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 @@
 		}
 	}
 
-free_romx:
+cleanup:
 	free(romx);
 }
 
@@ -1192,7 +1191,7 @@
 		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 @@
 
 		close(input);
 	}
+finish:
 	if (nbErrors)
-fail:
 		fprintf(stderr, "Fixing \"%s\" failed with %u error%s\n",
 			name, nbErrors, nbErrors == 1 ? "" : "s");
 	return nbErrors;