Merge pull request #656 from simartin/ticket_6953

Ticket #6953: Fixed flawed logic in PR#650.
This commit is contained in:
amai2012 2015-08-28 06:01:13 +02:00
commit 2b17a5bcee
2 changed files with 18 additions and 2 deletions

View File

@ -1025,7 +1025,7 @@ void CheckClass::checkMemset()
if (var->isArrayOrPointer()) { if (var->isArrayOrPointer()) {
const Token *endTok = var->typeEndToken(); const Token *endTok = var->typeEndToken();
while (endTok && Token::simpleMatch(endTok, "*")) { while (endTok && Token::simpleMatch(endTok, "*")) {
--numIndirToVariableType; ++numIndirToVariableType;
endTok = endTok->previous(); endTok = endTok->previous();
} }
} }

View File

@ -2581,7 +2581,23 @@ private:
" memset(c2, 0, 10);\n" " memset(c2, 0, 10);\n"
" memset(c3, 0, 10);\n" " memset(c3, 0, 10);\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:12]: (error) Using 'memset' on struct that contains a 'std::string'.\n", errout.str()); ASSERT_EQUALS("[test.cpp:9]: (error) Using 'memset' on struct that contains a 'std::string'.\n"
"[test.cpp:11]: (error) Using 'memset' on struct that contains a 'std::string'.\n"
"[test.cpp:12]: (error) Using 'memset' on struct that contains a 'std::string'.\n"
"[test.cpp:13]: (error) Using 'memset' on struct that contains a 'std::string'.\n", errout.str());
// Ticket #6953
checkNoMemset("typedef float realnum;\n"
"struct multilevel_data {\n"
" realnum *GammaInv;\n"
" realnum data[1];\n"
"};\n"
"void *new_internal_data() const {\n"
" multilevel_data *d = (multilevel_data *) malloc(sizeof(multilevel_data));\n"
" memset(d, 0, sizeof(multilevel_data));\n"
" return (void*) d;\n"
"}");
ASSERT_EQUALS("[test.cpp:8]: (portability) Using memset() on struct which contains a floating point number.\n", errout.str());
} }
void memsetOnStdPodType() { // Ticket #5901 void memsetOnStdPodType() { // Ticket #5901