Merge pull request #2927 from kugelfuhr/kugelfuhr/fix-2926

Fix cc65 not detecting invalid integer and float literal suffixes
This commit is contained in:
Bob Andrews
2026-02-11 19:54:44 +01:00
committed by GitHub
2 changed files with 14 additions and 9 deletions

View File

@@ -558,6 +558,7 @@ static void NumericConst (void)
unsigned DigitVal;
scan_t IVal; /* Scanned value. */
int Overflow;
unsigned SuffixStart;
/* Get the pp-number first, then parse on it */
CopyPPNumber (&Src);
@@ -641,6 +642,7 @@ static void NumericConst (void)
** possible to convert the data to unsigned long even if the IT_ULONG
** flag were not set, but we are not doing that.
*/
SuffixStart = SB_GetIndex (&Src);
if (toupper (SB_Peek (&Src)) == 'U') {
/* Unsigned type */
SB_Skip (&Src);
@@ -661,11 +663,6 @@ static void NumericConst (void)
Types = IT_ULONG;
}
} else {
if (SB_Peek (&Src) != '\0') {
Error ("Invalid suffix \"%s\" on integer constant",
SB_GetConstBuf (&Src) + SB_GetIndex (&Src));
}
if (Base == 10) {
/* Decimal constants are of any type but uint */
Types = IT_INT | IT_LONG | IT_ULONG;
@@ -676,6 +673,12 @@ static void NumericConst (void)
}
}
/* Check for remaining suffix characters */
if (SB_Peek (&Src) != '\0') {
Error ("Invalid suffix \"%s\" on integer constant",
SB_GetConstBuf (&Src) + SuffixStart);
}
/* Check the range to determine the type */
if (IVal > 0x7FFF) {
/* Out of range for int */
@@ -806,16 +809,17 @@ static void NumericConst (void)
}
/* Check for a suffix and determine the type of the constant */
SuffixStart = SB_GetIndex (&Src);
if (toupper (SB_Peek (&Src)) == 'F') {
SB_Skip (&Src);
NextTok.Type = type_float;
} else {
if (SB_Peek (&Src) != '\0') {
Error ("Invalid suffix \"%s\" on floating constant",
SB_GetConstBuf (&Src) + SB_GetIndex (&Src));
}
NextTok.Type = type_double;
}
if (SB_Peek (&Src) != '\0') {
Error ("Invalid suffix \"%s\" on floating constant",
SB_GetConstBuf (&Src) + SuffixStart);
}
/* Set the value and the token */
NextTok.FVal = FVal;

1
test/err/bug2926.c Normal file
View File

@@ -0,0 +1 @@
int main() { int a = 42LFOOBAR; return 0; }