From 023a3c037f102fcaa5e037b762c33d3537a67472 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Sun, 12 Apr 2020 22:52:32 +0200 Subject: [PATCH] Properly handle missing symbols Fixes #512 --- src/link/patch.c | 6 +++++- test/link/sym-noexist.asm | 3 +++ test/link/sym-noexist.out | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 test/link/sym-noexist.asm create mode 100644 test/link/sym-noexist.out diff --git a/src/link/patch.c b/src/link/patch.c index d9f56cea..aeab74b2 100644 --- a/src/link/patch.c +++ b/src/link/patch.c @@ -337,7 +337,11 @@ static int32_t computeRPNExpr(struct Patch const *patch, symbol = getSymbol(fileSymbols, value); - if (strcmp(symbol->name, "@")) { + if (!symbol) { + error("%s: Unknown symbol \"%s\"", + patch->fileName, + fileSymbols[value]->name); + } else if (strcmp(symbol->name, "@")) { value = symbol->value; /* Symbols attached to sections have offsets */ if (symbol->section) diff --git a/test/link/sym-noexist.asm b/test/link/sym-noexist.asm new file mode 100644 index 00000000..f6232128 --- /dev/null +++ b/test/link/sym-noexist.asm @@ -0,0 +1,3 @@ +SECTION "Test", ROM0 + jp where + dw nothing diff --git a/test/link/sym-noexist.out b/test/link/sym-noexist.out new file mode 100644 index 00000000..035c6e3a --- /dev/null +++ b/test/link/sym-noexist.out @@ -0,0 +1,3 @@ +error: sym-noexist.asm(3): Unknown symbol "nothing" +error: sym-noexist.asm(2): Unknown symbol "where" +Linking failed with 2 errors