Ticket #5201: Get rid of internal error when checking valid C input for memory leaks.
This commit is contained in:
parent
2b490b32b2
commit
6019f45249
|
@ -7020,6 +7020,13 @@ bool Tokenizer::simplifyRedundantParentheses()
|
|||
tok->deleteNext();
|
||||
ret = true;
|
||||
}
|
||||
|
||||
if (Token::Match(tok->previous(), "[,;{}] ( %var% ) .")) {
|
||||
// Remove the parentheses
|
||||
tok->deleteThis();
|
||||
tok->deleteNext();
|
||||
ret = true;
|
||||
}
|
||||
|
||||
if (Token::Match(tok->previous(), "[(,;{}] ( %var% (") &&
|
||||
tok->link()->previous() == tok->linkAt(2)) {
|
||||
|
|
|
@ -5110,7 +5110,7 @@ public:
|
|||
}
|
||||
|
||||
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..
|
||||
errout.str("");
|
||||
|
||||
|
@ -5119,7 +5119,7 @@ private:
|
|||
// Tokenize..
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
std::istringstream istr(code);
|
||||
tokenizer.tokenize(istr, fname ? fname : "test.cpp");
|
||||
tokenizer.tokenize(istr, fname ? fname : (isCPP ? "test.cpp" : "test.c"));
|
||||
tokenizer.simplifyTokenList2();
|
||||
|
||||
// Check for memory leaks..
|
||||
|
@ -5166,6 +5166,7 @@ private:
|
|||
// Segmentation fault in CheckMemoryLeakStructMember
|
||||
TEST_CASE(trac5030);
|
||||
|
||||
TEST_CASE(varid); // #5201: Analysis confused by (variable).attribute notation
|
||||
}
|
||||
|
||||
void err() {
|
||||
|
@ -5464,6 +5465,19 @@ private:
|
|||
"}");
|
||||
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