Skip to content

Commit ee3108b

Browse files
committed
fix
1 parent f294a7e commit ee3108b

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
@@ -8944,6 +8944,15 @@ void Tokenizer::findGarbageCode() const
89448944
"typedef",
89458945
"while" };
89468946

8947+
const auto isTooLargeInt = [](const Token *tok) {
8948+
try {
8949+
(void)MathLib::toBigUNumber(tok);
8950+
return false;
8951+
} catch (const InternalError & /*e*/) {
8952+
return true;
8953+
}
8954+
};
8955+
89478956
for (const Token *tok = tokens(); tok; tok = tok->next()) {
89488957
// initialization: = {
89498958
if (Token::simpleMatch(tok, "= {") && Token::simpleMatch(tok->linkAt(1), "} ("))
@@ -8995,6 +9004,19 @@ void Tokenizer::findGarbageCode() const
89959004
syntaxError(tok);
89969005
}
89979006

9007+
// Invalid integer literal as argument of a possible macro
9008+
if (tok->isNumber() && MathLib::isInt(tok->str()) && isTooLargeInt(tok)) {
9009+
const Token *prev = tok->previous();
9010+
while (prev && !Token::Match(prev, "(|;|{|}")) {
9011+
if (Token::Match(prev, ")|]"))
9012+
prev = prev->link();
9013+
prev = prev->previous();
9014+
}
9015+
if (prev && prev->str() == "(" && Token::Match(prev->previous(), "%name% (") && !prev->previous()->isKeyword())
9016+
unknownMacroError(prev->previous());
9017+
syntaxError(tok, "integer literal too large");
9018+
}
9019+
89989020
if (tok->isControlFlowKeyword()) {
89999021
if (Token::Match(tok, "if|while|for|switch")) { // if|while|for|switch (EXPR) { ... }
90009022
if (tok->previous() && !Token::Match(tok->previous(), "%name%|:|;|{|}|)")) {

0 commit comments

Comments
 (0)