fix #1288 (Use of memset on struct - nested structs not handled)

This commit is contained in:
Robert Reif 2011-03-23 21:58:58 -04:00
parent cbc81e20f5
commit 61e720c82b
2 changed files with 16 additions and 1 deletions

View File

@ -725,7 +725,9 @@ void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Sco
if (Token::simpleMatch(tok1, "std ::") && !Token::Match(var->nameToken()->previous(), "*|&"))
memsetError(tok, tok->str(), "'std::" + tok1->strAt(2) + "'", type->classDef->str());
/** @todo warn if type is class/struct that doesn't require initialization */
// check for known type that is not a pointer or reference
else if (var->type() && !Token::Match(var->nameToken()->previous(), "*|&"))
checkMemsetType(start, tok, var->type());
}
}
}

View File

@ -3142,6 +3142,19 @@ private:
" memset(&fred, 0, sizeof(fred));\n"
"}\n");
ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on struct that contains a 'std::string'\n", errout.str());
checkNoMemset("struct Stringy {\n"
" std::string inner;\n"
"};\n"
"struct Foo {\n"
" Stringy s;\n"
"}\n"
"int main() {\n"
" Foo foo;\n"
" memset(&foo, 0, sizeof(Foo));\n"
"}\n");
ASSERT_EQUALS("[test.cpp:9]: (error) Using 'memset' on struct that contains a 'std::string'\n", errout.str());
}
void memsetVector()