scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 7bef3d1fcbbb59778de9e883f818978696a39617
parent 09944e394b7a4474d0a13a8628164cd1fe170472
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat, 31 Oct 2015 09:37:49 +0100

Fix escape sequences parsing

We were not incrementing the pointer in the case of escape sequences of only
1 letter, and it was generating garbage fat the end of the character.

Diffstat:
cc1/lex.c | 24++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/cc1/lex.c b/cc1/lex.c @@ -398,16 +398,16 @@ escape(void) int c, base; switch (*++input->p) { - case '\\': return '\\'; - case 'a': return '\a'; - case 'f': return '\f'; - case 'n': return '\n'; - case 'r': return '\r'; - case 't': return '\t'; - case 'v': return '\v'; - case '\'': return '\\'; - case '"': return'"'; - case '?': return '?'; + case '\\': c = '\\'; goto escape_letter; + case 'a': c = '\a'; goto escape_letter; + case 'f': c = '\f'; goto escape_letter; + case 'n': c = '\n'; goto escape_letter; + case 'r': c = '\r'; goto escape_letter; + case 't': c = '\t'; goto escape_letter; + case 'v': c = '\v'; goto escape_letter; + case '\'': c = '\\'; goto escape_letter; + case '"': c = '"'; goto escape_letter; + case '?': c = '?'; goto escape_letter; case 'u': base = 10; break; case 'x': base = 16; break; case '0': base = 8; break; @@ -420,6 +420,10 @@ escape(void) if (errno || c > 255) warn("character constant out of range"); return c; + +escape_letter: + ++input->p; + return c; } static unsigned