ref: 25efb00769cb1a16fe3ab643e4b63d33402a5bcc
parent: c6c7b99fadba635b03653c784c5c03a3edd1ac25
author: Christophe Staïesse <[email protected]>
date: Fri Oct 10 11:22:00 EDT 2014
fix a bug in the lexer involving double quote escaping and semicolons The bug showed up when a semicolon was located anywhere after \". These three test cases are syntaxically correct but didn't compile: 1) SECTION "HOME", HOME db "\";" 2) SECTION "HOME", HOME db "\"" nop ; 3) SECTION "HOME", HOME db "\"" ; The problem was located in yy_create_buffer(). Basicaly, this function loads an entire source file, uniformizes EOL terminators and filters out comments without touching literal strings. However, bounds of literal strings were wrongly guessed because \" was interpreted as two characters (and so the double quote was not escaped). In test 1, the string terminates early and so ;" is filtered out as it was a comment and so the assembler complains of an unterminated string. In test 2 and 3, the string is in fact interpreted as two strings, the second one terminates at EOF in these cases and so comments are not filtered out and that makes the assembler complains. A special case must be taken into account: 4) SECTION "HOME", HOME db "\\" ; So we need to ignore \\ as well. Note that there is still a problem left: in yy_create_buffer() a string may span multiple lines but not in the lexer. However in this case I think the lexer would quit at the first newline so there should be nothing to worry about.
--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -164,7 +164,10 @@
if (*mem == '\"')
instring = 1 - instring;
- if (instring) {
+ if (mem[0] == '\\' &&
+ (mem[1] == '\"' || mem[1] == '\\')) {
+ mem += 2;
+ } else if (instring) {
mem += 1;
} else {
if ((mem[0] == 10 && mem[1] == 13)