Merge pull request #208 from simartin/ticket_5201
Ticket #5201: Get rid of internal error when checking valid C input for leaks
This commit is contained in:
commit
f1054a50f6
|
@ -7020,6 +7020,13 @@ bool Tokenizer::simplifyRedundantParentheses()
|
||||||
tok->deleteNext();
|
tok->deleteNext();
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Token::Match(tok->previous(), "[,;{}] ( %var% ) .")) {
|
||||||
|
// Remove the parentheses
|
||||||
|
tok->deleteThis();
|
||||||
|
tok->deleteNext();
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (Token::Match(tok->previous(), "[(,;{}] ( %var% (") &&
|
if (Token::Match(tok->previous(), "[(,;{}] ( %var% (") &&
|
||||||
tok->link()->previous() == tok->linkAt(2)) {
|
tok->link()->previous() == tok->linkAt(2)) {
|
||||||
|
|
|
@ -5110,7 +5110,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void check(const char code[], const char fname[] = 0) {
|
void check(const char code[], const char fname[] = 0, bool isCPP = true) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
||||||
|
@ -5119,7 +5119,7 @@ private:
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
tokenizer.tokenize(istr, fname ? fname : "test.cpp");
|
tokenizer.tokenize(istr, fname ? fname : (isCPP ? "test.cpp" : "test.c"));
|
||||||
tokenizer.simplifyTokenList2();
|
tokenizer.simplifyTokenList2();
|
||||||
|
|
||||||
// Check for memory leaks..
|
// Check for memory leaks..
|
||||||
|
@ -5166,6 +5166,7 @@ private:
|
||||||
// Segmentation fault in CheckMemoryLeakStructMember
|
// Segmentation fault in CheckMemoryLeakStructMember
|
||||||
TEST_CASE(trac5030);
|
TEST_CASE(trac5030);
|
||||||
|
|
||||||
|
TEST_CASE(varid); // #5201: Analysis confused by (variable).attribute notation
|
||||||
}
|
}
|
||||||
|
|
||||||
void err() {
|
void err() {
|
||||||
|
@ -5464,6 +5465,19 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void varid() { // #5201
|
||||||
|
check("struct S {\n"
|
||||||
|
" void *state_check_buff;\n"
|
||||||
|
"};\n"
|
||||||
|
"void f() {\n"
|
||||||
|
" S s;\n"
|
||||||
|
" (s).state_check_buff = (void* )malloc(1);\n"
|
||||||
|
" if (s.state_check_buff == 0)\n"
|
||||||
|
" return;\n"
|
||||||
|
"}", /*fname=*/0, /*isCPP=*/false);
|
||||||
|
ASSERT_EQUALS("[test.c:9]: (error) Memory leak: s.state_check_buff\n", errout.str());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue