From c423ee346aae7a7af025298f5fb788ac8d331d07 Mon Sep 17 00:00:00 2001 From: Olaf Seibert Date: Mon, 1 Jun 2015 23:30:16 +0200 Subject: [PATCH] Handle invalid expressions in .WORD directives with a message. This is most relevant in implied .WORD directives which are caused by an attempt to call a macro (which happens to be undefined) with arguments that don't parse as valid expressions. --- assemble_aux.c | 9 +++++++-- tests/RunTests | 13 ++++++++++++- tests/test-impword.mac | 12 ++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 tests/test-impword.mac diff --git a/assemble_aux.c b/assemble_aux.c index e5c4177..a5b7180 100644 --- a/assemble_aux.c +++ b/assemble_aux.c @@ -653,9 +653,14 @@ int do_word( } else { EX_TREE *value = parse_expr(cp, 0); - store_value(stack, tr, size, value); + if (value->cp > cp) { + store_value(stack, tr, size, value); - cp = value->cp; + cp = value->cp; + } else { + report(stack->top, "Invalid expression in .WORD\n"); + cp = ""; /* force loop to end */ + } free_tree(value); } diff --git a/tests/RunTests b/tests/RunTests index b80f350..7f96aaf 100755 --- a/tests/RunTests +++ b/tests/RunTests @@ -6,7 +6,18 @@ # If there is a .objd.ok file, it compares the result of dumpobj. # -TESTS="test-asciz test-backpatch test-bsl-mac-arg test-complex-reloc test-endm test-include test-jmp test-locals test-macro-comma test-undef test-word-comma" +TESTS="test-asciz \ + test-backpatch \ + test-bsl-mac-arg \ + test-complex-reloc \ + test-endm \ + test-impword \ + test-include \ + test-jmp \ + test-locals \ + test-macro-comma \ + test-undef \ + test-word-comma" for t in $TESTS do diff --git a/tests/test-impword.mac b/tests/test-impword.mac new file mode 100644 index 0000000..839d6e1 --- /dev/null +++ b/tests/test-impword.mac @@ -0,0 +1,12 @@ +;;;;; +; +; Test the implied .word construction +; + +start: 3 + start + ; The following could be a macro which by accident is not defined + ; which takes arguments that don't parse as expressions. + macro 8-BIT,1,2,3 + ; The following can by accident be parsed as an expression. + macro 7-BIT,1,2,3