#4195 segmentation fault of cppcheck (invalid code). Fix segfault which turned up after refactoring the enum handling code.

This commit is contained in:
Alexander Mai 2016-05-17 22:19:23 +02:00
parent 4f77a2b044
commit 303a85a930
3 changed files with 9 additions and 6 deletions

View File

@ -7978,6 +7978,8 @@ void Tokenizer::simplifyComma()
tok = tok->link()->next();
}
if (!tok)
syntaxError(nullptr); // invalid code like in #4195
if (Token::Match(tok, "(|[") ||
(tok->str() == "{" && tok->previous() && tok->previous()->str() == "=")) {
tok = tok->link();

View File

@ -230,6 +230,7 @@ private:
TEST_CASE(garbageCode179); // #3533
TEST_CASE(garbageCode180);
TEST_CASE(garbageCode181);
TEST_CASE(garbageCode182); // #4195
TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase);
TEST_CASE(garbageAST);
@ -1509,6 +1510,12 @@ private:
void garbageCode181() {
checkCode("int test() { int +; }");
}
// #4195 - segfault for "enum { int f ( ) { return = } r = f ( ) ; }"
void garbageCode182() {
ASSERT_THROW(checkCode("enum { int f ( ) { return = } r = f ( ) ; }"), InternalError);
}
};
REGISTER_TEST(TestGarbage)

View File

@ -59,7 +59,6 @@ private:
TEST_CASE(tokenize20); // replace C99 _Bool => bool
TEST_CASE(tokenize21); // tokenize 0x0E-7
TEST_CASE(tokenize22); // special marker $ from preprocessor
TEST_CASE(tokenize24); // #4195 (segmentation fault)
TEST_CASE(tokenize25); // #4239 (segmentation fault)
TEST_CASE(tokenize26); // #4245 (segmentation fault)
TEST_CASE(tokenize27); // #4525 (segmentation fault)
@ -745,11 +744,6 @@ private:
ASSERT_EQUALS("$if ( ! p )", tokenizeAndStringify("$if(!p)"));
}
// #4195 - segfault for "enum { int f ( ) { return = } r = f ( ) ; }"
void tokenize24() {
TODO_ASSERT_THROW(tokenizeAndStringify("enum { int f ( ) { return = } r = f ( ) ; }"), InternalError);
}
// #4239 - segfault for "f ( struct { int typedef T x ; } ) { }"
void tokenize25() {
tokenizeAndStringify("f ( struct { int typedef T x ; } ) { }");