ref: c5e8e4ff83c70ddf32f00bfa69f0d4f918af3c15
parent: 17b9838c8fdf8f74edf741ac05a45affe0332089
author: dbrotz <[email protected]>
date: Mon Sep 9 13:27:56 EDT 2019
Reject input that contains null characters Null characters in the middle of strings interact badly with the RGBDS codebase, which assumes null-terminated strings. There is no reason to support null characters in input source code, so the simplest way to deal with null characters is to reject them early.
--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -269,6 +269,7 @@
/* Convert all line endings to LF and spaces */
char *mem = pBuffer->pBuffer;
+ int32_t lineCount = 0;
while (*mem) {
if ((mem[0] == '\\') && (mem[1] == '\"' || mem[1] == '\\')) {
@@ -279,13 +280,20 @@
|| ((mem[0] == '\r') && (mem[1] == '\n'))) {
*mem++ = ' ';
*mem++ = '\n';
+ lineCount++;
/* LF and CR */
} else if ((mem[0] == '\n') || (mem[0] == '\r')) {
*mem++ = '\n';
+ lineCount++;
} else {
mem++;
}
}
+ }
+
+ if (mem != pBuffer->pBuffer + size) {
+ nLineNo = lineCount + 1;
+ fatalerror("Found null character");
}
/* Remove comments */
--- a/test/asm/null-in-macro.out
+++ b/test/asm/null-in-macro.out
@@ -1,2 +1,2 @@
-ERROR: null-in-macro.asm(1):
- Unterminated MACRO definition.
+ERROR: null-in-macro.asm(2):
+ Found null character