diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 5f9ee4809a7..a8b41b5b176 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -910,6 +910,9 @@ namespace { Token* const tok4 = useAfterVarRange ? insertTokens(after->previous(), mRangeAfterVar)->next() : tok3->next(); + if (tok->next() == tok4) + throw InternalError(tok, "Failed to simplify typedef. Is the code valid?"); + tok->deleteThis(); // Unsplit variable declarations @@ -8695,6 +8698,10 @@ void Tokenizer::findGarbageCode() const } if (Token::Match(tok, "%num%|%bool%|%char%|%str% %num%|%bool%|%char%|%str%") && !Token::Match(tok, "%str% %str%")) syntaxError(tok); + if (Token::Match(tok, "%num%|%bool%|%char%|%str% {") && + !(tok->tokType() == Token::Type::eString && Token::simpleMatch(tok->tokAt(-1), "extern")) && + !(tok->tokType() == Token::Type::eBoolean && cpp && Token::simpleMatch(tok->tokAt(-1), "requires"))) + syntaxError(tok); if (Token::Match(tok, "%assign% typename|class %assign%")) syntaxError(tok); if (Token::Match(tok, "%assign% [;)}]") && (!cpp || !Token::simpleMatch(tok->previous(), "operator"))) diff --git a/test/cli/fuzz-crash/crash-c021b973c9f8692ff1ea73710209a4129dc7a834 b/test/cli/fuzz-crash/crash-c021b973c9f8692ff1ea73710209a4129dc7a834 new file mode 100644 index 00000000000..411936bf04e --- /dev/null +++ b/test/cli/fuzz-crash/crash-c021b973c9f8692ff1ea73710209a4129dc7a834 @@ -0,0 +1 @@ +typedef const C;C(public C