File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -914,10 +914,6 @@ void CheckClass::noMemset()
914914 // 3 arguments.
915915 continue ;
916916
917- // Check if it's not a pointer to pointer
918- if (arg1->variable () && arg1->variable ()->typeEndToken () &&
919- Token::Match (arg1->variable ()->typeEndToken ()->previous (), " * *" ))
920- continue ;
921917
922918 const Token *typeTok = 0 ;
923919 const Scope *type = 0 ;
@@ -942,8 +938,12 @@ void CheckClass::noMemset()
942938
943939 const Variable *var = arg1->variable ();
944940 if (var && arg1->strAt (1 ) == " ," ) {
945- if (var->isPointer ())
941+ if (var->isPointer ()) {
946942 derefs--;
943+ if (var->typeEndToken () && Token::Match (var->typeEndToken ()->previous (), " * *" )) // Check if it's a pointer to pointer
944+ derefs--;
945+ }
946+
947947 if (var->isArray ())
948948 derefs -= (int )var->dimensions ().size ();
949949
Original file line number Diff line number Diff line change @@ -2406,16 +2406,19 @@ class TestClass : public TestFixture {
24062406 " C* c1[10][10];\n "
24072407 " C* c2[10];\n "
24082408 " C c3[10][10];\n "
2409+ " C** c4 = new C*[10];\n "
24092410 " memset(**c1, 0, 10);\n "
24102411 " memset(*c1, 0, 10);\n "
24112412 " memset(*c2, 0, 10);\n "
24122413 " memset(*c3, 0, 10);\n "
2414+ " memset(*c4, 0, 10);\n "
24132415 " memset(c2, 0, 10);\n "
24142416 " memset(c3, 0, 10);\n "
24152417 " }" );
2416- ASSERT_EQUALS (" [test.cpp:8]: (error) Using 'memset' on struct that contains a 'std::string'.\n "
2417- " [test.cpp:10]: (error) Using 'memset' on struct that contains a 'std::string'.\n "
2418- " [test.cpp:11]: (error) Using 'memset' on struct that contains a 'std::string'.\n " , errout.str ());
2418+ ASSERT_EQUALS (" [test.cpp:9]: (error) Using 'memset' on struct that contains a 'std::string'.\n "
2419+ " [test.cpp:11]: (error) Using 'memset' on struct that contains a 'std::string'.\n "
2420+ " [test.cpp:12]: (error) Using 'memset' on struct that contains a 'std::string'.\n "
2421+ " [test.cpp:13]: (error) Using 'memset' on struct that contains a 'std::string'.\n " , errout.str ());
24192422 }
24202423
24212424 void mallocOnClass () {
You can’t perform that action at this time.
0 commit comments