Skip to content

Commit

Permalink
Fix #12313 FP mallocOnClassWarning when malloc'd pointer is passed to…
Browse files Browse the repository at this point in the history
… implicit conversion (#6019)
  • Loading branch information
chrchr-github committed Feb 22, 2024
1 parent 5b8ddaf commit 8d079f2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1429,7 +1429,7 @@ void CheckClass::checkMemset()
const std::set<const Scope *> parsedTypes;
checkMemsetType(scope, tok, type, false, parsedTypes);
}
} else if (tok->variable() && tok->variable()->typeScope() && Token::Match(tok, "%var% = %name% (")) {
} else if (tok->variable() && tok->variable()->isPointer() && tok->variable()->typeScope() && Token::Match(tok, "%var% = %name% (")) {
const Library::AllocFunc* alloc = mSettings->library.getAllocFuncInfo(tok->tokAt(2));
if (!alloc)
alloc = mSettings->library.getReallocFuncInfo(tok->tokAt(2));
Expand Down
9 changes: 9 additions & 0 deletions test/testclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3598,6 +3598,15 @@ class TestClass : public TestFixture {
" AutoCloseFD fd = open(\"abc\", O_RDONLY | O_CLOEXEC);\n"
"}");
ASSERT_EQUALS("", errout.str());

checkNoMemset("struct C {\n" // #12313
" char* p;\n"
" C(char* ptr) : p(ptr) {}\n"
"};\n"
"void f() {\n"
" C c = strdup(\"abc\");\n"
"}");
ASSERT_EQUALS("", errout.str());
}

#define checkThisSubtraction(code) checkThisSubtraction_(code, __FILE__, __LINE__)
Expand Down

0 comments on commit 8d079f2

Please sign in to comment.