Fixed even more problems with the range check.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5171 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2011-08-15 17:23:44 +00:00
parent cd50385b72
commit b097b49a4a

View file

@ -329,7 +329,7 @@ void SegCheck (void)
/* Check the segments for range and other errors */ /* Check the segments for range and other errors */
{ {
static const unsigned long U_Hi[4] = { static const unsigned long U_Hi[4] = {
0x000000FFL, 0x0000FFFFL, 0x00FFFFFFL, 0xFFFFFFFFL 0x000000FFUL, 0x0000FFFFUL, 0x00FFFFFFUL, 0xFFFFFFFFUL
}; };
static const long S_Hi[4] = { static const long S_Hi[4] = {
0x0000007FL, 0x00007FFFL, 0x007FFFFFL, 0x7FFFFFFFL 0x0000007FL, 0x00007FFFL, 0x007FFFFFL, 0x7FFFFFFFL
@ -353,22 +353,24 @@ void SegCheck (void)
/* Check if the expression is constant */ /* Check if the expression is constant */
if (ED_IsConst (&ED)) { if (ED_IsConst (&ED)) {
long Hi, Lo;
unsigned J; unsigned J;
/* The expression is constant. Check for range errors. */ /* The expression is constant. Check for range errors. */
CHECK (F->Len <= 4); CHECK (F->Len <= 4);
if (F->Type == FRAG_SEXPR) { if (F->Type == FRAG_SEXPR) {
Hi = S_Hi[F->Len-1]; long Hi = S_Hi[F->Len-1];
Lo = ~Hi; long Lo = ~Hi;
if (ED.Val > Hi || ED.Val < Lo) {
LIError (&F->LI,
"Range error (%ld not in [%ld..%ld])",
ED.Val, Lo, Hi);
}
} else { } else {
Hi = U_Hi[F->Len-1]; if (((unsigned long)ED.Val) > U_Hi[F->Len-1]) {
Lo = 0; LIError (&F->LI,
} "Range error (%lu not in [0..%lu])",
if (ED.Val > Hi || ED.Val < Lo) { (unsigned long)ED.Val, U_Hi[F->Len-1]);
LIError (&F->LI, }
"Range error (%ld not in [%ld..%ld])",
ED.Val, Lo, Hi);
} }
/* We don't need the expression tree any longer */ /* We don't need the expression tree any longer */