Skip to content

Commit

Permalink
Merge pull request #5204 from WalterBright/lexer-overflow
Browse files Browse the repository at this point in the history
lexer.d: avoid expensive overflow check
  • Loading branch information
9rnsr committed Oct 20, 2015
2 parents 7cd0374 + d935129 commit 521f076
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/lexer.d
Expand Up @@ -1832,16 +1832,14 @@ public:
default:
goto Ldone;
}
uinteger_t n2 = n * base;
if ((n2 / base != n || n2 + d < n))
{
overflow = true;
}
n = n2 + d;
// if n needs more than 64 bits
if (n.sizeof > 8 && n > 0xFFFFFFFFFFFFFFFFUL)
// Avoid expensive overflow check if we aren't at risk of overflow
if (n <= 0x0FFF_FFFF_FFFF_FFFFUL)
n = n * base + d;
else
{
overflow = true;
import core.checkedint;
n = mulu(n, base, overflow);
n = addu(n, d, overflow);
}
}
Ldone:
Expand Down

0 comments on commit 521f076

Please sign in to comment.