From 6c20f4b2a28bf643a50b7e00cb5b0ccabdb15346 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Wed, 4 Nov 2015 10:10:20 +0100 Subject: [PATCH] Fixed crash on garbage code (#7090) --- lib/tokenize.cpp | 4 ++-- test/testgarbage.cpp | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 0fc89d294..09a126b25 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -347,8 +347,8 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name, const Token return false; } } - - tok = tok->previous(); + if (tok) + tok = tok->previous(); } if ((*tokPtr)->strAt(1) != "(" || !Token::Match((*tokPtr)->linkAt(1), ") .|(|[")) { diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index f96d86f1c..d9fbf57f7 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -196,6 +196,7 @@ private: TEST_CASE(garbageCode145); // #7074 TEST_CASE(garbageCode146); // #7081 TEST_CASE(garbageCode147); // #7082 + TEST_CASE(garbageCode148); // #7090 TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); @@ -1168,6 +1169,14 @@ private: checkCode("; void f ^ { return } int main ( ) { }"); // #4941 } + void garbageCode148() { // #7090 + ASSERT_THROW(checkCode("void f_1() {\n" + " typedef S0 b[][1][1] != 0\n" + "};\n" + "b[K][0] S0 b[][1][1] != 4{ 0 };\n" + "b[0][0]"), InternalError); + } + void garbageValueFlow() { // #6089 const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"