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

This commit is contained in:
Anthony J. Bentley
2015-01-30 20:30:33 -07:00
parent 5702995978
commit 60c3a7e2f3

View File

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