Merge branch 'master' of git@github.com:danmar/cppcheck

This commit is contained in:
Reijo Tomperi 2009-09-24 23:47:28 +03:00
commit 2594f9b63f
2 changed files with 11 additions and 13 deletions

View File

@ -1017,7 +1017,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
addtoken("dealloc"); addtoken("dealloc");
addtoken(";"); addtoken(";");
addtoken("}"); addtoken("}");
tok = tok->tokAt(2); tok = tok->next()->link();
continue; continue;
} }
} }

View File

@ -338,9 +338,7 @@ private:
ASSERT_EQUALS(";;if(!var){}else{}", getcode("char *s; if (!s) { } else { }", "s")); ASSERT_EQUALS(";;if(!var){}else{}", getcode("char *s; if (!s) { } else { }", "s"));
ASSERT_EQUALS(";;if{}", getcode("char *s; if (a && s) { }", "s")); ASSERT_EQUALS(";;if{}", getcode("char *s; if (a && s) { }", "s"));
ASSERT_EQUALS(";;if(!var){}", getcode("char *s; if (a && !s) { }", "s")); ASSERT_EQUALS(";;if(!var){}", getcode("char *s; if (a && !s) { }", "s"));
ASSERT_EQUALS(";;;if{dealloc;};if{dealloc;return;}assign;returnuse;", getcode("char *buf, *tmp; tmp = realloc(buf, 40); if (!(tmp)) { free(buf); return; } buf = tmp; return buf;", "buf"));
// There are missing semicolons in the extracted code
TODO_ASSERT_EQUALS(";;;if{dealloc;}if{dealloc;return;}assign;returnuse;", getcode("char *buf, *tmp; tmp = realloc(buf, 40); if (!(tmp)) { free(buf); return; } buf = tmp; return buf;", "buf"));
// switch.. // switch..
ASSERT_EQUALS(";;switch{case;break;};", getcode("char *s; switch(a){case 1: break;};", "s")); ASSERT_EQUALS(";;switch{case;break;};", getcode("char *s; switch(a){case 1: break;};", "s"));
@ -1527,17 +1525,17 @@ private:
{ {
check("void foo()\n" check("void foo()\n"
"{\n" "{\n"
"char *buf;\n" " char *buf;\n"
"char *new_buf;\n" " char *new_buf;\n"
"buf = calloc( 10 );\n" " buf = calloc( 10 );\n"
"new_buf = realloc ( buf, 20);\n" " new_buf = realloc ( buf, 20);\n"
"if ( !new_buf )\n" " if ( !new_buf )\n"
" free(buf);\n" " free(buf);\n"
"else\n" " else\n"
" free(new_buf);\n" " free(new_buf);\n"
"}\n", true); "}\n", true);
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("[test.cpp:11]: (possible error) Memory leak: buf\n", errout.str());
} }
void realloc6() void realloc6()