Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cfg/opencv2.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<noreturn>false</noreturn>
<returnValue type="void"/>
<arg nr="1">
<not-uninit indirect="1"/>
<not-uninit/>
</arg>
</function>
<!-- void * cv::fastMalloc (size_t bufSize) -->
Expand Down
6 changes: 6 additions & 0 deletions lib/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,20 +1075,26 @@ bool Library::isuninitargbad(const Token *ftok, int argnr, int indirect, bool *h
/** get allocation info for function */
const Library::AllocFunc* Library::getAllocFuncInfo(const Token *tok) const
{
while (Token::simpleMatch(tok, "::"))
tok = tok->astOperand2() ? tok->astOperand2() : tok->astOperand1();
const std::string funcname = getFunctionName(tok);
return isNotLibraryFunction(tok) && functions.find(funcname) != functions.end() ? nullptr : getAllocDealloc(mAlloc, funcname);
}

/** get deallocation info for function */
const Library::AllocFunc* Library::getDeallocFuncInfo(const Token *tok) const
{
while (Token::simpleMatch(tok, "::"))
tok = tok->astOperand2() ? tok->astOperand2() : tok->astOperand1();
const std::string funcname = getFunctionName(tok);
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
{
while (Token::simpleMatch(tok, "::"))
tok = tok->astOperand2() ? tok->astOperand2() : tok->astOperand1();
const std::string funcname = getFunctionName(tok);
return isNotLibraryFunction(tok) && functions.find(funcname) != functions.end() ? nullptr : getAllocDealloc(mRealloc, funcname);
}
Expand Down
9 changes: 6 additions & 3 deletions test/cfg/opencv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ void validCode(const char* argStr)
cvStr += " World";
std::cout << cvStr;

char * pBuf = (char *)cv::fastMalloc(20); // cppcheck-suppress cstyleCast
// cppcheck-suppress [cstyleCast, unusedAllocatedMemory]
char * pBuf = (char *)cv::fastMalloc(20);
cv::fastFree(pBuf);
}

Expand All @@ -42,7 +43,9 @@ void ignoredReturnValue()

void memleak()
{
const char * pBuf = (char *)cv::fastMalloc(1000); // cppcheck-suppress cstyleCast
std::cout << pBuf; // cppcheck-suppress valueFlowBailoutIncompleteVar
// cppcheck-suppress cstyleCast
const char * pBuf = (char *)cv::fastMalloc(1000);
// cppcheck-suppress [uninitdata, valueFlowBailoutIncompleteVar]
std::cout << pBuf;
// cppcheck-suppress memleak
}
6 changes: 3 additions & 3 deletions test/cfg/std.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2928,7 +2928,7 @@ void uninitvar_longjmp(void)
void uninitvar_malloc(void)
{
size_t size;
// cppcheck-suppress [uninitvar, cstyleCast]
// cppcheck-suppress [uninitvar, cstyleCast, unusedAllocatedMemory]
int *p = (int*)std::malloc(size);
free(p);
}
Expand Down Expand Up @@ -4957,7 +4957,7 @@ void std_vector_data_arithmetic()

void memleak_std_malloc() // #12332
{
//cppcheck-suppress [unreadVariable, constVariablePointer]
//cppcheck-suppress [unreadVariable, constVariablePointer, unusedAllocatedMemory]
void* p = std::malloc(1);
//cppcheck-suppress memleak
}
Expand All @@ -4971,7 +4971,7 @@ void memleak_std_realloc(void* block, size_t newsize)

void unusedAllocatedMemory_std_free()
{
// TODO cppcheck-suppress unusedAllocatedMemory
// cppcheck-suppress unusedAllocatedMemory
void* p = std::malloc(1);
std::free(p);
}
Expand Down