From 6ee1fd2a677c4ee497b5c087b4356a7b783a9b75 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sat, 19 Nov 2016 13:02:19 +0000 Subject: [PATCH 1/2] scanner: Correct handling of \0101 The C language has this oddity that octal constants are 3 bytes so the sequence "\0101" is two bytes and well defined by the langage. cc65 currently misparses this as a 1 byte octal code. Add a count to fix this. Signed-off-by: Alan Cox --- src/cc65/scanner.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc65/scanner.c b/src/cc65/scanner.c index 16d43e2ea..d867c9857 100644 --- a/src/cc65/scanner.c +++ b/src/cc65/scanner.c @@ -267,6 +267,7 @@ static int ParseChar (void) { int C; int HadError; + int Count; /* Check for escape chars */ if (CurC == '\\') { @@ -337,8 +338,9 @@ static int ParseChar (void) case '7': /* Octal constant */ HadError = 0; + Count = 1; C = HexVal (CurC); - while (IsODigit (NextC)) { + while (IsODigit (NextC) && Count++ < 3) { if ((C << 3) >= 256) { if (!HadError) { Error ("Octal character constant out of range"); From e4aee2ba340d32ab9042fc86070e0bd263a50ba1 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sun, 20 Nov 2016 18:02:45 +0000 Subject: [PATCH 2/2] cc65: remove un-needed logic from octal parsing We no longer need the extra error handling logic for octal parsing so simplify it as requested by Greg King. Signed-off-by: Alan Cox --- src/cc65/scanner.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/cc65/scanner.c b/src/cc65/scanner.c index d867c9857..c9009bc2f 100644 --- a/src/cc65/scanner.c +++ b/src/cc65/scanner.c @@ -337,20 +337,14 @@ static int ParseChar (void) case '6': case '7': /* Octal constant */ - HadError = 0; Count = 1; C = HexVal (CurC); while (IsODigit (NextC) && Count++ < 3) { - if ((C << 3) >= 256) { - if (!HadError) { - Error ("Octal character constant out of range"); - HadError = 1; - } - } else { - C = (C << 3) | HexVal (NextC); - } + C = (C << 3) | HexVal (NextC); NextChar (); } + if (C >= 256) + Error ("Octal character constant out of range"); break; default: Error ("Illegal character constant");