#7023 segmentation fault (invalid code) in astIsIntegral. Avoid crash, unfortunately there is no syntax error yet detected.

This commit is contained in:
amai2012 2015-10-06 11:21:31 +02:00
parent e99b4319c9
commit 88b3d90505
3 changed files with 9 additions and 2 deletions

View File

@ -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"))

View File

@ -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;
}

View File

@ -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"