1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-10 19:29:45 +00:00

Merge pull request #358 from EtchedPixels/master

* 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 <etchedpixels@gmail.com>

* 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 <etchedpixels@gmail.com>
This commit is contained in:
greg-king5 2016-11-26 17:30:38 -05:00 committed by GitHub
commit f4c51046f0

View File

@ -267,6 +267,7 @@ static int ParseChar (void)
{ {
int C; int C;
int HadError; int HadError;
int Count;
/* Check for escape chars */ /* Check for escape chars */
if (CurC == '\\') { if (CurC == '\\') {
@ -336,19 +337,14 @@ static int ParseChar (void)
case '6': case '6':
case '7': case '7':
/* Octal constant */ /* Octal constant */
HadError = 0; Count = 1;
C = HexVal (CurC); C = HexVal (CurC);
while (IsODigit (NextC)) { while (IsODigit (NextC) && Count++ < 3) {
if ((C << 3) >= 256) { C = (C << 3) | HexVal (NextC);
if (!HadError) {
Error ("Octal character constant out of range");
HadError = 1;
}
} else {
C = (C << 3) | HexVal (NextC);
}
NextChar (); NextChar ();
} }
if (C >= 256)
Error ("Octal character constant out of range");
break; break;
default: default:
Error ("Illegal character constant"); Error ("Illegal character constant");