shithub: rgbds

Download patch

ref: 60c3a7e2f35e83c15e44b69f8a3274cd69acfe6a
parent: 57029959788a4e399fb8de1127866bd1b66c1115
author: Anthony J. Bentley <[email protected]>
date: Fri Jan 30 15:30:33 EST 2015

Reformat code for better spacing, and provide a more detailed error.

--- a/src/asm/output.c
+++ b/src/asm/output.c
@@ -440,24 +440,30 @@
 		errx(1, "Section '%s' cannot contain code or data (not a "
 		    "ROM0 or ROMX)", pCurrentSection->pzName);
 	}
-	if (pCurrentSection->nPC + size <= MAXSECTIONSIZE) {
-		if (((pCurrentSection->nPC % SECTIONCHUNK) >
-			((pCurrentSection->nPC + size) % SECTIONCHUNK))
-		    && (pCurrentSection->nType == SECT_ROM0
-			|| pCurrentSection->nType == SECT_ROMX)) {
-			if ((pCurrentSection->tData =
-				(UBYTE *) realloc(pCurrentSection->tData,
-				    ((pCurrentSection->nPC +
-					    size) / SECTIONCHUNK +
-					1) * SECTIONCHUNK)) != NULL) {
-				return;
-			} else
-				fatalerror
-				    ("Not enough memory to expand section");
+	if (pCurrentSection->nPC + size > MAXSECTIONSIZE) {
+		/*
+		 * N.B.: This check is not sufficient to ensure the section
+		 * will fit, because there can be multiple sections of this
+		 * type. The definitive check must be done at the linking
+		 * stage.
+		 */
+		errx(1, "Section '%s' is too big (old size %d + %d > %d)",
+		    pCurrentSection->pzName, pCurrentSection->nPC, size,
+		    MAXSECTIONSIZE);
+	}
+	if (((pCurrentSection->nPC % SECTIONCHUNK) >
+	    ((pCurrentSection->nPC + size) % SECTIONCHUNK)) &&
+	    (pCurrentSection->nType == SECT_ROM0 ||
+	    pCurrentSection->nType == SECT_ROMX)) {
+		pCurrentSection->tData = realloc(pCurrentSection->tData,
+		    ((pCurrentSection->nPC + size) / SECTIONCHUNK + 1) *
+		    SECTIONCHUNK);
+
+		if (pCurrentSection->tData == NULL) {
+			err(1, "Could not expand section");
 		}
-		return;
-	} else
-		errx(1, "Section '%s' is too big", pCurrentSection->pzName);
+	}
+	return;
 }
 
 /*