From f72fd6960e5093efaedd32e9d28ce6645fc8b040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 16 Jan 2011 11:54:28 +0100 Subject: [PATCH] Fixed #2449 (segfault in tokenize.cpp, incorrect parsing) --- lib/tokenize.cpp | 21 +++++++++++++++++++++ test/testtokenize.cpp | 7 +++++++ 2 files changed, 28 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 7b7951af9..249ebc656 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2385,6 +2385,27 @@ bool Tokenizer::tokenize(std::istream &code, // Remove __builtin_expect, likely and unlikely simplifyBuiltinExpect(); + // #2449: syntax error: enum with typedef in it + for (const Token *tok = _tokens; tok; tok = tok->next()) + { + if (Token::Match(tok, "enum %var% {")) + { + for (const Token *tok2 = tok->tokAt(3); tok2; tok2 = tok2->next()) + { + if (tok2->str() == "typedef") + { + syntaxError(tok2); + deallocateTokens(); + return false; + } + else if (tok2->str() == "}") + { + break; + } + } + } + } + // typedef.. simplifyTypedef(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 25089a374..ee5207b96 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -511,6 +511,13 @@ private: ASSERT_EQUALS("", tokenizeAndStringify(code.c_str(), true)); ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str()); } + + { + errout.str(""); + const std::string code("enum ABC { A,B, typedef enum { C } };"); + tokenizeAndStringify(code.c_str(), true); + ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str()); + } } void minus()