shithub: rgbds

Download patch

ref: 311b412f5dcd53c4e0898680319052b12209f4e0
parent: 975200834ecefd2c05b5f7b292172d222fa751e8
author: Antonio Niño Díaz <[email protected]>
date: Tue Jan 16 17:38:20 EST 2018

Improve error messages

NULL error messages have been given a description.

Messages that weren't descriptive enough now also print the name of the
function that has failed.

Signed-off-by: Antonio Niño Díaz <[email protected]>

--- a/src/asm/output.c
+++ b/src/asm/output.c
@@ -200,7 +200,7 @@
 		sec = sec->pNext;
 	}
 
-	fatalerror("INTERNAL: Unknown section");
+	fatalerror("%s: Unknown section", __func__);
 	return (uint32_t)(-1);
 }
 
--- a/src/link/assign.c
+++ b/src/link/assign.c
@@ -74,7 +74,7 @@
 void ensureSectionTypeIsValid(enum eSectionType type)
 {
 	if (type < SECT_MIN || type > SECT_MAX)
-		errx(1, "(INTERNAL) Invalid section type found.");
+		errx(1, "%s: Invalid section type found: %d", __func__, type);
 }
 
 int BankIndexIsROM0(int32_t bank)
@@ -162,7 +162,7 @@
 		pNewArea = malloc(sizeof(struct sFreeArea));
 
 		if (pNewArea == NULL)
-			err(1, NULL);
+			err(1, "%s: Failed to allocate memory", __func__);
 
 		*pNewArea = *pArea;
 		pNewArea->pPrev = pArea;
@@ -627,8 +627,10 @@
 		    && pSection->nOrg != -1 && pSection->nBank == -1))
 			continue;
 
-		if (options & OPT_OVERLAY)
-			errx(1, "All sections must be fixed when using an overlay file.");
+		if (options & OPT_OVERLAY) {
+			errx(1, "All sections must be fixed when using an overlay file: '%s'",
+			     pSection->pzName);
+		}
 
 		switch (pSection->Type) {
 		case SECT_ROMX:
--- a/src/link/object.c
+++ b/src/link/object.c
@@ -50,7 +50,7 @@
 	char *s = start;
 
 	if (!s)
-		err(1, NULL);
+		err(1, "%s: Couldn't allocate memory", __func__);
 
 	while (((*s++) = fgetc(f)) != 0) {
 		r += 1;
@@ -58,8 +58,10 @@
 		if (r >= bufferLength) {
 			bufferLength *= 2;
 			start = realloc(start, bufferLength);
-			if (!start)
-				err(1, NULL);
+			if (!start) {
+				err(1, "%s: Couldn't allocate memory",
+				    __func__);
+			}
 			s = start + r;
 		}
 	}
@@ -85,7 +87,7 @@
 
 	*ppSections = malloc(sizeof **ppSections);
 	if (!*ppSections)
-		err(1, NULL);
+		err(1, "%s: Couldn't allocate memory", __func__);
 
 	(*ppSections)->tSymbols = tSymbols;
 	(*ppSections)->pNext = NULL;
@@ -103,7 +105,7 @@
 
 	pSym = malloc(sizeof(*pSym));
 	if (!pSym)
-		err(1, NULL);
+		err(1, "%s: Couldn't allocate memory", __func__);
 
 	readasciiz(&pSym->pzName, f);
 	pSym->Type = (enum eSymbolType)fgetc(f);
@@ -205,7 +207,7 @@
 
 	pSection->pData = malloc(pSection->nByteSize);
 	if (!pSection->pData)
-		err(1, NULL);
+		err(1, "%s: Couldn't allocate memory", __func__);
 
 	int32_t nNumberOfPatches;
 	struct sPatch **ppPatch, *pPatch;
@@ -212,7 +214,7 @@
 
 	if (fread(pSection->pData, sizeof(uint8_t), pSection->nByteSize, f)
 	    != pSection->nByteSize) {
-		err(1, "Read error.");
+		err(1, "%s: Read error", __func__);
 	}
 
 	nNumberOfPatches = readlong(f);
@@ -224,7 +226,7 @@
 	while (nNumberOfPatches--) {
 		pPatch = malloc(sizeof(*pPatch));
 		if (!pPatch)
-			err(1, NULL);
+			err(1, "%s: Couldn't allocate memory", __func__);
 
 		*ppPatch = pPatch;
 		readasciiz(&pPatch->pzFilename, f);
@@ -235,12 +237,14 @@
 
 		if (pPatch->nRPNSize > 0) {
 			pPatch->pRPN = malloc(pPatch->nRPNSize);
-			if (!pPatch->pRPN)
-				err(1, NULL);
+			if (!pPatch->pRPN) {
+				err(1, "%s: Couldn't allocate memory",
+				    __func__);
+			}
 
 			if (fread(pPatch->pRPN, sizeof(uint8_t),
 				  pPatch->nRPNSize, f) != pPatch->nRPNSize) {
-				errx(1, "Read error.");
+				errx(1, "%s: Read error", __func__);
 			}
 		} else {
 			pPatch->pRPN = NULL;
@@ -266,7 +270,7 @@
 	if (nNumberOfSymbols) {
 		tSymbols = malloc(nNumberOfSymbols * sizeof(*tSymbols));
 		if (!tSymbols)
-			err(1, NULL);
+			err(1, "%s: Couldn't allocate memory", __func__);
 
 		for (i = 0; i < nNumberOfSymbols; i += 1)
 			tSymbols[i] = obj_ReadSymbol(pObjfile, tzObjectfile);
@@ -318,7 +322,7 @@
 
 	if (fread(tzHeader, sizeof(char), strlen(RGBDS_OBJECT_VERSION_STRING),
 		  pObjfile) != strlen(RGBDS_OBJECT_VERSION_STRING)) {
-		errx(1, "%s: Read error.", tzObjectfile);
+		errx(1, "%s: Read error", tzObjectfile);
 	}
 
 	tzHeader[strlen(RGBDS_OBJECT_VERSION_STRING)] = 0;
--- a/src/link/script.c
+++ b/src/link/script.c
@@ -97,7 +97,7 @@
 {
 	if (strcmp(type, "ROM0") == 0) {
 		if (bank != 0)
-			errx(1, "(Internal) Trying to assign a bank number to ROM0.\n");
+			errx(1, "Trying to assign a bank number to ROM0.\n");
 		current_bank = BANK_INDEX_ROM0;
 		current_real_bank = 0;
 		return;
@@ -121,8 +121,7 @@
 		return;
 	} else if (strcmp(type, "WRAM0") == 0) {
 		if (bank != 0) {
-			errx(1, "%s: Trying to assign a bank number to WRAM0.\n",
-			     __func__);
+			errx(1, "Trying to assign a bank number to WRAM0.\n");
 		}
 		current_bank = BANK_INDEX_WRAM0;
 		current_real_bank = 0;
--- a/test/asm/null-in-macro.out
+++ b/test/asm/null-in-macro.out
@@ -1,2 +1,2 @@
 ERROR: null-in-macro.asm(1):
-	Unterminated MACRO definition
+	Unterminated MACRO definition.