Skip to content

Commit

Permalink
[CLI] Fix crash on non-existing include file
Browse files Browse the repository at this point in the history
  • Loading branch information
tgtakaoka committed Dec 21, 2023
1 parent 135ecc5 commit f366167
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
5 changes: 4 additions & 1 deletion driver/asm_directive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,11 @@ Error AsmDirective::includeFile(StrScanner &scan, Context &context) {
} else {
p = filename.takeWhile([](char s) { return !isspace(s); });
}
const auto error = context.sources.open(filename);
if (error)
setErrorIf(filename, error);
scan = p;
return setError(context.sources.open(filename));
return error;
}

Error AsmDirective::defineFunction(StrScanner &scan, Context &context) {
Expand Down
2 changes: 1 addition & 1 deletion driver/asm_formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ StrBuffer &AsmFormatter::getLine(StrBuffer &out) {
_formatter.formatDec(out, column);
}
out.rtext_P(PSTR(": error: ")).rtext_P(_error.errorText_P());
if (*_error.errorAt())
if (_error.errorAt() && *_error.errorAt())
out.rtext_P(PSTR(": \"")).rtext(_error.errorAt()).rletter('"');
_nextLine = -1;
} else {
Expand Down
27 changes: 27 additions & 0 deletions test/driver/test_asm_formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,32 @@ void test_forward_labels() {
" 9/ 1009 : =4 label5 equ 4\n");
}

void test_include() {
PREP_ASM(mc6809::AsmMc6809, MotorolaDirective);

TestReader exist("data/exist.inc");
sources.add(exist);
exist.add(" fcc /exist/\n");

driver.setUpperHex(true);
driver.setLineNumber(true);
driver.setOption("smart-branch", "on");

ASM("mc6809",
" cpu mc6809\n"
"* comment line\n"
" org $abcd\n"
" include \"data/exist.inc\"\n"
" include \"data/not-exist.inc\"\n",
" 1/ 0 : cpu mc6809\n"
" 2/ 0 : * comment line\n"
" 3/ ABCD : org $abcd\n"
" 4/ ABCD : include \"data/exist.inc\"\n"
"(1) 1/ ABCD : 65 78 69 73 74 fcc /exist/\n"
"mc6809:5:18: error: Include file not found: \"data/not-exist.inc\"\"\n"
" 5/ ABD2 : include \"data/not-exist.inc\"\n");
}

void run_tests() {
RUN_TEST(test_symbols_mc6809);
RUN_TEST(test_symbols_ins8060);
Expand All @@ -326,6 +352,7 @@ void run_tests() {
RUN_TEST(test_list_radix);
RUN_TEST(test_function);
RUN_TEST(test_forward_labels);
RUN_TEST(test_include);
}

} // namespace test
Expand Down

0 comments on commit f366167

Please sign in to comment.