diff --git a/lib/checkother.cpp b/lib/checkother.cpp index cf385c1ab..0f8fe51dc 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -309,7 +309,7 @@ void CheckOther::clarifyStatement() while (tok2 && tok2->str() == "*") tok2 = tok2->previous(); - if (Token::Match(tok2, "[{};]")) { + if (!tok2->astParent() && Token::Match(tok2, "[{};]")) { tok2 = tok->astOperand1(); if (Token::Match(tok2, "++|-- [;,]")) clarifyStatementError(tok2); diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 1bf0d0d51..3bf1c6c2a 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -75,6 +75,7 @@ private: TEST_CASE(garbageCode34); // #6626 TEST_CASE(garbageCode35); // #2599, #2604 TEST_CASE(garbageCode36); // #6334 + TEST_CASE(garbageCode37); // #5166 TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); @@ -430,6 +431,20 @@ private: checkCode("sizeof <= A"); } + void garbageCode36() { // #6334 + checkCode("{ } < class template < > , { = } ; class... >\n" + "struct Y { }\n" + "class Types { }\n" + "( X < int > \"uses template\" ) ( < ( ) \"uses ; \n" + "( int int ::primary \"uses template\" ) int double \"uses )\n" + "::primary , \"uses template\" ;\n"); + } + + void garbageCode37() { + // #5166 segmentation fault (invalid code) in lib/checkother.cpp:329 ( void * f { } void b ( ) { * f } ) + checkCode("void * f { } void b ( ) { * f }"); + } + void garbageValueFlow() { // #6089 const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n" @@ -544,15 +559,6 @@ private: "}\n" ); } - - void garbageCode36() { // #6334 - checkCode("{ } < class template < > , { = } ; class... >\n" - "struct Y { }\n" - "class Types { }\n" - "( X < int > \"uses template\" ) ( < ( ) \"uses ; \n" - "( int int ::primary \"uses template\" ) int double \"uses )\n" - "::primary , \"uses template\" ;\n"); - } }; REGISTER_TEST(TestGarbage) diff --git a/test/testother.cpp b/test/testother.cpp index d6c52c2f1..54b5a25e8 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -3843,8 +3843,9 @@ private: "}"); ASSERT_EQUALS("", errout.str()); - // #5166 segmentation fault (invalid code) in lib/checkother.cpp:329 ( void * f { } void b ( ) { * f } ) - check("void * f { } void b ( ) { * f }"); + check("void *f(char* p) {\n" + " for (p = path; *p++;) ;\n" + "}"); ASSERT_EQUALS("", errout.str()); }