fixed #4195 segmentation fault of cppcheck (invalid code); Added a testcase
This commit is contained in:
parent
07d2935e81
commit
3f89e38275
|
@ -7282,6 +7282,9 @@ void Tokenizer::simplifyEnum()
|
||||||
bool simplify = false;
|
bool simplify = false;
|
||||||
bool hasClass = false;
|
bool hasClass = false;
|
||||||
EnumValue *ev = NULL;
|
EnumValue *ev = NULL;
|
||||||
|
|
||||||
|
if (!tok1)
|
||||||
|
return;
|
||||||
for (Token *tok2 = tok1->next(); tok2; tok2 = tok2->next()) {
|
for (Token *tok2 = tok1->next(); tok2; tok2 = tok2->next()) {
|
||||||
if (tok2->str() == "}") {
|
if (tok2->str() == "}") {
|
||||||
--level;
|
--level;
|
||||||
|
|
|
@ -56,6 +56,7 @@ private:
|
||||||
TEST_CASE(tokenize21); // tokenize 0x0E-7
|
TEST_CASE(tokenize21); // tokenize 0x0E-7
|
||||||
TEST_CASE(tokenize22); // special marker $ from preprocessor
|
TEST_CASE(tokenize22); // special marker $ from preprocessor
|
||||||
TEST_CASE(tokenize23); // tokenize "return - __LINE__;"
|
TEST_CASE(tokenize23); // tokenize "return - __LINE__;"
|
||||||
|
TEST_CASE(tokenize24); // #4195 (segmentation fault)
|
||||||
|
|
||||||
// don't freak out when the syntax is wrong
|
// don't freak out when the syntax is wrong
|
||||||
TEST_CASE(wrong_syntax1);
|
TEST_CASE(wrong_syntax1);
|
||||||
|
@ -641,6 +642,11 @@ private:
|
||||||
ASSERT_EQUALS("return -1 ;", tokenizeAndStringify("return - __LINE__;"));
|
ASSERT_EQUALS("return -1 ;", tokenizeAndStringify("return - __LINE__;"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #4195 - segfault for "enum { int f ( ) { return = } r = f ( ) ; }"
|
||||||
|
void tokenize24() {
|
||||||
|
tokenizeAndStringify("enum { int f ( ) { return = } r = f ( ) ; }");
|
||||||
|
}
|
||||||
|
|
||||||
void wrong_syntax1() {
|
void wrong_syntax1() {
|
||||||
{
|
{
|
||||||
const std::string code("TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))");
|
const std::string code("TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))");
|
||||||
|
|
Loading…
Reference in New Issue