From f294a7e90950a93b4851eb14dc2326cdc82e4495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Wed, 2 Dec 2026 15:48:49 +0100 Subject: [PATCH 1/2] test --- test/testtokenize.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 7a8d2512b4f..ee1bedb12be 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -490,6 +490,7 @@ class TestTokenizer : public TestFixture { TEST_CASE(checkConfiguration); TEST_CASE(unknownMacroBeforeReturn); + TEST_CASE(unknownMacroTooLargeInt); TEST_CASE(cppKeywordInCSource); @@ -8853,6 +8854,15 @@ class TestTokenizer : public TestFixture { ASSERT_THROW_INTERNAL(tokenizeAndStringify("int f() { X return 0; }\n"), UNKNOWN_MACRO); } + void unknownMacroTooLargeInt() { + ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("int x = STR(123456789012345678901234567890123456789);\n"), + UNKNOWN_MACRO, + "There is an unknown macro here somewhere. Configuration is required. If STR is a macro then please configure it."); + ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("int x = 123456789012345678901234567890123456789;\n"), + SYNTAX, + "syntax error: integer literal too large"); + } + void cppKeywordInCSource() { ASSERT_NO_THROW(tokenizeAndStringify("int throw() {}\n", dinit(TokenizeOptions, $.cpp = false))); From ee3108b0115eb0e17d3ccecaf1fd16e6d9940a53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Wed, 2 Dec 2026 15:48:54 +0100 Subject: [PATCH 2/2] fix --- lib/tokenize.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 72873ac2475..e37f9b1dccd 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8944,6 +8944,15 @@ void Tokenizer::findGarbageCode() const "typedef", "while" }; + const auto isTooLargeInt = [](const Token *tok) { + try { + (void)MathLib::toBigUNumber(tok); + return false; + } catch (const InternalError & /*e*/) { + return true; + } + }; + for (const Token *tok = tokens(); tok; tok = tok->next()) { // initialization: = { if (Token::simpleMatch(tok, "= {") && Token::simpleMatch(tok->linkAt(1), "} (")) @@ -8995,6 +9004,19 @@ void Tokenizer::findGarbageCode() const syntaxError(tok); } + // Invalid integer literal as argument of a possible macro + if (tok->isNumber() && MathLib::isInt(tok->str()) && isTooLargeInt(tok)) { + const Token *prev = tok->previous(); + while (prev && !Token::Match(prev, "(|;|{|}")) { + if (Token::Match(prev, ")|]")) + prev = prev->link(); + prev = prev->previous(); + } + if (prev && prev->str() == "(" && Token::Match(prev->previous(), "%name% (") && !prev->previous()->isKeyword()) + unknownMacroError(prev->previous()); + syntaxError(tok, "integer literal too large"); + } + if (tok->isControlFlowKeyword()) { if (Token::Match(tok, "if|while|for|switch")) { // if|while|for|switch (EXPR) { ... } if (tok->previous() && !Token::Match(tok->previous(), "%name%|:|;|{|}|)")) {