From 25efb00769cb1a16fe3ab643e4b63d33402a5bcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christophe=20Sta=C3=AFesse?= Date: Fri, 10 Oct 2014 15:22:00 +0200 Subject: [PATCH] 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. --- src/asm/lexer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/asm/lexer.c b/src/asm/lexer.c index 8d6a8a25..92288425 100644 --- a/src/asm/lexer.c +++ b/src/asm/lexer.c @@ -164,7 +164,10 @@ yy_create_buffer(FILE * f) 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)