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 <antonio_nd@outlook.com>
This commit is contained in:
Antonio Niño Díaz
2018-01-16 22:38:20 +00:00
parent 975200834e
commit 311b412f5d
5 changed files with 27 additions and 22 deletions

View File

@@ -200,7 +200,7 @@ static uint32_t getsectid(struct Section *pSect)
sec = sec->pNext;
}
fatalerror("INTERNAL: Unknown section");
fatalerror("%s: Unknown section", __func__);
return (uint32_t)(-1);
}

View File

@@ -74,7 +74,7 @@ static void do_max_bank(enum eSectionType Type, int32_t nBank)
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 @@ int32_t area_doAlloc(struct sFreeArea *pArea, int32_t org, int32_t size)
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 @@ void AssignSections(void)
&& 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:

View File

@@ -50,7 +50,7 @@ int32_t readasciiz(char **dest, FILE *f)
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 @@ int32_t readasciiz(char **dest, FILE *f)
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 @@ struct sSection *AllocSection(void)
*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 @@ struct sSymbol *obj_ReadSymbol(FILE *f, char *tzObjectfile)
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,14 +207,14 @@ struct sSection *obj_ReadRGBSection(FILE *f)
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;
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 @@ struct sSection *obj_ReadRGBSection(FILE *f)
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 @@ struct sSection *obj_ReadRGBSection(FILE *f)
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 @@ void obj_ReadRGB(FILE *pObjfile, char *tzObjectfile)
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 @@ void obj_ReadOpenFile(FILE *pObjfile, char *tzObjectfile)
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;

View File

@@ -97,7 +97,7 @@ void script_SetCurrentSectionType(const char *type, uint32_t bank)
{
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 @@ void script_SetCurrentSectionType(const char *type, uint32_t bank)
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;

View File

@@ -1,2 +1,2 @@
ERROR: null-in-macro.asm(1):
Unterminated MACRO definition
Unterminated MACRO definition.