File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -841,7 +841,7 @@ const Token * CheckLeakAutoVar::checkTokenInsideExpression(const Token * const t
841841 if (rhs->varId () == tok->varId ()) {
842842 // simple assignment
843843 varInfo.erase (tok->varId ());
844- } else if (rhs->str () == " (" && !mSettings ->library .returnValue (rhs->astOperand1 ()).empty ()) {
844+ } else if (rhs->astParent () && rhs-> str () == " (" && !mSettings ->library .returnValue (rhs->astOperand1 ()).empty ()) {
845845 // #9298, assignment through return value of a function
846846 const std::string &returnValue = mSettings ->library .returnValue (rhs->astOperand1 ());
847847 if (startsWith (returnValue, " arg" )) {
Original file line number Diff line number Diff line change @@ -2999,6 +2999,7 @@ class TestLeakAutoVarStrcpy : public TestFixture {
29992999 TEST_CASE (returnedValue); // #9298
30003000 TEST_CASE (deallocuse2);
30013001 TEST_CASE (fclose_false_positive); // #9575
3002+ TEST_CASE (strcpy_false_negative);
30023003 }
30033004
30043005 void returnedValue () { // #9298
@@ -3037,6 +3038,13 @@ class TestLeakAutoVarStrcpy : public TestFixture {
30373038 ASSERT_EQUALS (" " , errout.str ());
30383039 }
30393040
3041+ void strcpy_false_negative () { // #12289
3042+ check (" void f() {\n "
3043+ " char* buf = new char[12];\n "
3044+ " strcpy(buf, \" 123\" );\n "
3045+ " }\n " );
3046+ ASSERT_EQUALS (" [test.cpp:4]: (error) Memory leak: buf\n " , errout.str ());
3047+ }
30403048};
30413049
30423050REGISTER_TEST (TestLeakAutoVarStrcpy)
You can’t perform that action at this time.
0 commit comments