Skip to content

Commit 3395e60

Browse files
committed
fix
1 parent 090a5b8 commit 3395e60

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎lib/tokenize.cpp‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8976,6 +8976,15 @@ void Tokenizer::findGarbageCode() const
89768976
return false;
89778977
};
89788978

8979+
const auto isTooLargeInt = [](const Token *tok) {
8980+
try {
8981+
(void)MathLib::toBigUNumber(tok);
8982+
return false;
8983+
} catch (const InternalError & /*e*/) {
8984+
return true;
8985+
}
8986+
};
8987+
89798988
for (const Token *tok = tokens(); tok; tok = tok->next()) {
89808989
// initialization: = {
89818990
if (Token::simpleMatch(tok, "= {") && Token::simpleMatch(tok->linkAt(1), "} ("))
@@ -9038,6 +9047,19 @@ void Tokenizer::findGarbageCode() const
90389047
unknownMacroError(par->previous());
90399048
}
90409049

9050+
// Invalid integer literal as argument of a possible macro
9051+
if (tok->isNumber() && MathLib::isInt(tok->str()) && isTooLargeInt(tok)) {
9052+
const Token *prev = tok->previous();
9053+
while (prev && !Token::Match(prev, "(|;|{|}")) {
9054+
if (Token::Match(prev, ")|]"))
9055+
prev = prev->link();
9056+
prev = prev->previous();
9057+
}
9058+
if (prev && prev->str() == "(" && Token::Match(prev->previous(), "%name% (") && !prev->previous()->isKeyword())
9059+
unknownMacroError(prev->previous());
9060+
syntaxError(tok, "integer literal too large");
9061+
}
9062+
90419063
if (tok->isControlFlowKeyword()) {
90429064
if (Token::Match(tok, "if|while|for|switch")) { // if|while|for|switch (EXPR) { ... }
90439065
if (tok->previous() && !Token::Match(tok->previous(), "%name%|:|;|{|}|)")) {

0 commit comments

Comments
 (0)