From f6d929a9f72d50d7f0a2469a4460bdcee4497bc7 Mon Sep 17 00:00:00 2001 From: chrchr Date: Thu, 11 Jan 2024 11:52:54 +0100 Subject: [PATCH] std::realloc --- lib/library.cpp | 8 +++++--- test/cfg/std.cpp | 7 +++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/library.cpp b/lib/library.cpp index b172bdc6914..d28d6e02070 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -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); } @@ -1070,7 +1070,7 @@ 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); } @@ -1078,7 +1078,9 @@ const Library::AllocFunc* Library::getDeallocFuncInfo(const Token *tok) const /** 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); } diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index 455a36528cc..40a4314419b 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -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