ref: 4e1d79081c3aba476daf38ba42180281752a8e3b
parent: 045a9e8b93048379b60afc9992d6f245d5129a89
author: Jakub Kądziołka <kuba@kadziolka.net>
date: Mon Oct 12 18:54:38 EDT 2020
Improve error message for negative shift arguments
--- a/src/asm/macro.c
+++ b/src/asm/macro.c
@@ -130,9 +130,11 @@
void macro_ShiftCurrentArgs(int32_t count)
{
- if (!macroArgs)
+ if (!macroArgs) {
error("Cannot shift macro arguments outside of a macro\n");
- else if (macroArgs->shift < macroArgs->nbArgs) {
+ } else if (count < 0) {
+ error("Cannot shift arguments by negative amount %" PRId32 "\n", count);
+ } else if (macroArgs->shift < macroArgs->nbArgs) {
macroArgs->shift += count;
if (macroArgs->shift > macroArgs->nbArgs)
macroArgs->shift = macroArgs->nbArgs;
--- a/src/asm/parser.y
+++ b/src/asm/parser.y
@@ -580,7 +580,7 @@
;
shift : T_POP_SHIFT { macro_ShiftCurrentArgs(1); }
- | T_POP_SHIFT uconst { macro_ShiftCurrentArgs($2); }
+ | T_POP_SHIFT const { macro_ShiftCurrentArgs($2); }
;
load : T_POP_LOAD string ',' sectiontype sectorg sectattrs {
--- /dev/null
+++ b/test/asm/shift-negative.asm
@@ -1,0 +1,4 @@
+m: MACRO
+ shift -3
+ENDM
+ m
--- /dev/null
+++ b/test/asm/shift-negative.err
@@ -1,0 +1,3 @@
+ERROR: shift-negative.asm(4) -> shift-negative.asm::m(2):
+ Cannot shift arguments by negative amount -3
+error: Assembly aborted (1 errors)!