Skip to content

Commit

Permalink
std::realloc
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Jan 11, 2024
1 parent c1c91a3 commit f6d929a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ bool Library::isuninitargbad(const Token *ftok, int argnr, int indirect, bool *h
const Library::AllocFunc* Library::getAllocFuncInfo(const Token *tok) const
{
std::string funcname = getFunctionName(tok);
if (startsWith(funcname, "std::"))
if (tok->isCpp() && startsWith(funcname, "std::"))
funcname.erase(0, 5);
return isNotLibraryFunction(tok) && functions.find(funcname) != functions.end() ? nullptr : getAllocDealloc(mAlloc, funcname);
}
Expand All @@ -1070,15 +1070,17 @@ const Library::AllocFunc* Library::getAllocFuncInfo(const Token *tok) const
const Library::AllocFunc* Library::getDeallocFuncInfo(const Token *tok) const
{
std::string funcname = getFunctionName(tok);
if (startsWith(funcname, "std::"))
if (tok->isCpp() && startsWith(funcname, "std::"))
funcname.erase(0, 5);
return isNotLibraryFunction(tok) && functions.find(funcname) != functions.end() ? nullptr : getAllocDealloc(mDealloc, funcname);
}

/** get reallocation info for function */
const Library::AllocFunc* Library::getReallocFuncInfo(const Token *tok) const
{
const std::string funcname = getFunctionName(tok);
std::string funcname = getFunctionName(tok);
if (tok->isCpp() && startsWith(funcname, "std::"))
funcname.erase(0, 5);
return isNotLibraryFunction(tok) && functions.find(funcname) != functions.end() ? nullptr : getAllocDealloc(mRealloc, funcname);
}

Expand Down
7 changes: 7 additions & 0 deletions test/cfg/std.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4872,6 +4872,13 @@ void memleak_std_malloc() // #12332
//cppcheck-suppress memleak
}

void memleak_std_realloc(void* block, size_t newsize)
{
//cppcheck-suppress [unreadVariable, constVariablePointer]
void* p = std::realloc(block, newsize);
//cppcheck-suppress memleak
}

void unusedAllocatedMemory_std_free()
{
//cppcheck-suppress unusedAllocatedMemory
Expand Down

0 comments on commit f6d929a

Please sign in to comment.