From 88b3d90505063e1de5088fe7b99abeb63fd4d9e6 Mon Sep 17 00:00:00 2001 From: amai2012 Date: Tue, 6 Oct 2015 11:21:31 +0200 Subject: [PATCH] #7023 segmentation fault (invalid code) in astIsIntegral. Avoid crash, unfortunately there is no syntax error yet detected. --- lib/astutils.cpp | 2 +- lib/symboldatabase.h | 2 +- test/testgarbage.cpp | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) 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"