Improved memset with 0 bytes check. TODO done (unit test).
Patch from: PKEuS <philipp.kloke@web.de>
This commit is contained in:
parent
91c6608175
commit
3568b5a841
|
@ -1337,10 +1337,12 @@ void CheckOther::udivError(const Token *tok)
|
|||
//---------------------------------------------------------------------------
|
||||
void CheckOther::checkMemsetZeroBytes()
|
||||
{
|
||||
const Token *tok = _tokenizer->tokens();
|
||||
while (tok && ((tok = Token::findmatch(tok, "memset ( %var% , %num% , 0 )")) != NULL)) {
|
||||
memsetZeroBytesError(tok, tok->strAt(2));
|
||||
tok = tok->tokAt(8);
|
||||
for (const Token* tok = _tokenizer->tokens(); tok; tok = tok->next()) {
|
||||
if (Token::simpleMatch(tok, "memset (")) {
|
||||
const Token* lastParamTok = tok->tokAt(1)->link()->tokAt(-1);
|
||||
if (lastParamTok->str() == "0")
|
||||
memsetZeroBytesError(tok, tok->strAt(2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2701,7 +2701,7 @@ private:
|
|||
|
||||
void memsetZeroBytes() {
|
||||
check("void f() {\n"
|
||||
" memset(p, 10, 0);\n"
|
||||
" memset(p, 10, 0x0);\n"
|
||||
"}\n"
|
||||
);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (warning) memset() called to fill 0"
|
||||
|
@ -2711,10 +2711,14 @@ private:
|
|||
" memset(p, sizeof(p), 0);\n"
|
||||
"}\n"
|
||||
);
|
||||
TODO_ASSERT_EQUALS("[test.cpp:2]: (warning) memset() called to fill 0"
|
||||
" bytes of \"p\". Second and third arguments might be inverted.\n",
|
||||
ASSERT_EQUALS("[test.cpp:2]: (warning) memset() called to fill 0"
|
||||
" bytes of \'p\'\n", errout.str());
|
||||
|
||||
"", errout.str());
|
||||
check("void f() {\n"
|
||||
" memset(p, sizeof(p), i+0);\n"
|
||||
"}\n"
|
||||
);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void sizeofForArrayParameter() {
|
||||
|
|
Loading…
Reference in New Issue