diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 9565d1466..34d26643b 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -47,7 +47,7 @@ bool astIsIntegral(const Token *tok, bool unknown) return false; // Function call - if (tok->previous()->function()) { + if (tok->previous() && tok->previous()->function()) { if (Token::Match(tok->previous()->function()->retDef, "float|double")) return false; else if (Token::Match(tok->previous()->function()->retDef, "bool|char|short|int|long")) diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index 55909de58..aea05da64 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -1075,7 +1075,7 @@ public: ret = "float"; else if (type == DOUBLE) ret = "double"; - for (int p = 0; p < pointer; p++) + for (unsigned int p = 0; p < pointer; p++) ret += "*"; return ret; } diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 254095c4e..b89ef5e9b 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -170,6 +170,7 @@ private: TEST_CASE(garbageCode128); // #7018 TEST_CASE(garbageCode129); // #7020 TEST_CASE(garbageCode130); // #7021 + TEST_CASE(garbageCode131); // #7023 TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); @@ -983,6 +984,12 @@ private: InternalError); } + void garbageCode131() { + checkCode("( void ) { ( ) } ( ) / { ( ) }"); + // actually the invalid code should trigger an syntax error... + } + + void garbageValueFlow() { // #6089 const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"