From db7ce1c13c03e40c95e6d397e09667f0813d153f Mon Sep 17 00:00:00 2001 From: Chuck Larson Date: Thu, 24 Feb 2011 18:38:45 +0100 Subject: [PATCH] memset: using memset on struct/class that has std::string member variable. ticket: #1655 --- lib/checkclass.cpp | 12 ++++++++++++ test/testclass.cpp | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) 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()