1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-26 17:36:57 +00:00

Error check for internal overflow of numerical constant

See bug #2026
This commit is contained in:
bbbradsmith 2023-05-02 21:27:02 -04:00
parent 805e98a7aa
commit bf5b37a3b2

View File

@ -522,6 +522,7 @@ static void NumericConst (void)
char C;
unsigned DigitVal;
unsigned long IVal; /* Value */
int Overflow;
/* Get the pp-number first, then parse on it */
CopyPPNumber (&Src);
@ -575,6 +576,7 @@ static void NumericConst (void)
/* Since we now know the correct base, convert the input into a number */
SB_SetIndex (&Src, Index);
IVal = 0;
Overflow = 0;
while ((C = SB_Peek (&Src)) != '\0' && (Base <= 10 ? IsDigit (C) : IsXDigit (C))) {
DigitVal = HexVal (C);
if (DigitVal >= Base) {
@ -582,9 +584,17 @@ static void NumericConst (void)
SB_Clear (&Src);
break;
}
IVal = (IVal * Base) + DigitVal;
if ((((unsigned long)(IVal * Base)) / Base) != IVal)
Overflow = 1;
IVal = IVal * Base;
if (((unsigned long)(IVal + DigitVal)) < IVal)
Overflow = 1;
IVal += DigitVal;
SB_Skip (&Src);
}
if (Overflow)
Error ("Numerical constant \"%s\" too large for internal 32-bit representation",
SB_GetConstBuf (&Src));
/* Distinguish between integer and floating point constants */
if (!IsFloat) {