diff --git a/lib/checkother.cpp b/lib/checkother.cpp index c37528c40..274048bdb 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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)); + } } } diff --git a/test/testother.cpp b/test/testother.cpp index 7987765f6..df9adf085 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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() {