From 0665146dcdfd83c5f8576a4fbf8a26240e268d0a Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Tue, 21 Jan 2020 03:12:43 +0100 Subject: [PATCH] Report line info on empty RPN stack --- src/link/patch.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/link/patch.c b/src/link/patch.c index e70f1f89..1da0ea45 100644 --- a/src/link/patch.c +++ b/src/link/patch.c @@ -52,10 +52,11 @@ static void pushRPN(int32_t value) stack.size++; } -static int32_t popRPN(void) +static int32_t popRPN(char const *fileName, int32_t lineNo) { if (stack.size == 0) - errx(1, "Internal error, RPN stack empty"); + errx(1, "%s(%d): Internal error, RPN stack empty", fileName, + lineNo); stack.size--; return stack.buf[stack.size]; @@ -85,6 +86,9 @@ static uint8_t getRPNByte(uint8_t const **expression, int32_t *size, static int32_t computeRPNExpr(struct Patch const *patch, struct Section const *section) { +/* Small shortcut to avoid a lot of repetition */ +#define popRPN() popRPN(patch->fileName, patch->lineNo) + uint8_t const *expression = patch->rpnExpression; int32_t size = patch->rpnSize; @@ -287,6 +291,8 @@ static int32_t computeRPNExpr(struct Patch const *patch, patch->fileName, patch->lineNo, stack.size); return popRPN(); + +#undef popRPN } /**