diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index b13143d80..b4b54a6dc 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -712,6 +712,18 @@ void CheckClass::noMemset() type = tok->strAt(10); else if (Token::Match(tok, "%type% ( %var% , %var% , sizeof ( %type% ) )")) type = tok->strAt(8); + else if (Token::Match(tok, "memset ( & %var% , %num% , sizeof ( %var% ) )")) + { + unsigned int varid = tok->tokAt(3)->varId(); + for (const Token *lookback = tok->previous(); lookback; lookback = lookback->previous()) + { + if (Token::Match(lookback, "%type% %varid%",varid)) + { + type = lookback->str(); + break; + } + } + } // No type defined => The tokens didn't match if (type.empty()) diff --git a/test/testclass.cpp b/test/testclass.cpp index a4f727618..5bf3fb8f0 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -2966,7 +2966,7 @@ private: " Fred fred;\n" " memset(&fred, 0, sizeof(fred));\n" "}\n"); - TODO_ASSERT_EQUALS("error", "", errout.str()); + ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on struct that contains a 'std::string'\n", errout.str()); } void memsetVector()