Skip to content

Commit 5dcf217

Browse files
Fix FN unusedAllocatedMemory (f'up to #12332) (#6158)
See #6154
1 parent 427e8e9 commit 5dcf217

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

cfg/opencv2.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
<noreturn>false</noreturn>
7070
<returnValue type="void"/>
7171
<arg nr="1">
72-
<not-uninit indirect="1"/>
72+
<not-uninit/>
7373
</arg>
7474
</function>
7575
<!-- void * cv::fastMalloc (size_t bufSize) -->

lib/library.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,20 +1075,26 @@ bool Library::isuninitargbad(const Token *ftok, int argnr, int indirect, bool *h
10751075
/** get allocation info for function */
10761076
const Library::AllocFunc* Library::getAllocFuncInfo(const Token *tok) const
10771077
{
1078+
while (Token::simpleMatch(tok, "::"))
1079+
tok = tok->astOperand2() ? tok->astOperand2() : tok->astOperand1();
10781080
const std::string funcname = getFunctionName(tok);
10791081
return isNotLibraryFunction(tok) && functions.find(funcname) != functions.end() ? nullptr : getAllocDealloc(mAlloc, funcname);
10801082
}
10811083

10821084
/** get deallocation info for function */
10831085
const Library::AllocFunc* Library::getDeallocFuncInfo(const Token *tok) const
10841086
{
1087+
while (Token::simpleMatch(tok, "::"))
1088+
tok = tok->astOperand2() ? tok->astOperand2() : tok->astOperand1();
10851089
const std::string funcname = getFunctionName(tok);
10861090
return isNotLibraryFunction(tok) && functions.find(funcname) != functions.end() ? nullptr : getAllocDealloc(mDealloc, funcname);
10871091
}
10881092

10891093
/** get reallocation info for function */
10901094
const Library::AllocFunc* Library::getReallocFuncInfo(const Token *tok) const
10911095
{
1096+
while (Token::simpleMatch(tok, "::"))
1097+
tok = tok->astOperand2() ? tok->astOperand2() : tok->astOperand1();
10921098
const std::string funcname = getFunctionName(tok);
10931099
return isNotLibraryFunction(tok) && functions.find(funcname) != functions.end() ? nullptr : getAllocDealloc(mRealloc, funcname);
10941100
}

test/cfg/opencv2.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ void validCode(const char* argStr)
3030
cvStr += " World";
3131
std::cout << cvStr;
3232

33-
char * pBuf = (char *)cv::fastMalloc(20); // cppcheck-suppress cstyleCast
33+
// cppcheck-suppress [cstyleCast, unusedAllocatedMemory]
34+
char * pBuf = (char *)cv::fastMalloc(20);
3435
cv::fastFree(pBuf);
3536
}
3637

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

4344
void memleak()
4445
{
45-
const char * pBuf = (char *)cv::fastMalloc(1000); // cppcheck-suppress cstyleCast
46-
std::cout << pBuf; // cppcheck-suppress valueFlowBailoutIncompleteVar
46+
// cppcheck-suppress cstyleCast
47+
const char * pBuf = (char *)cv::fastMalloc(1000);
48+
// cppcheck-suppress [uninitdata, valueFlowBailoutIncompleteVar]
49+
std::cout << pBuf;
4750
// cppcheck-suppress memleak
4851
}

test/cfg/std.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2928,7 +2928,7 @@ void uninitvar_longjmp(void)
29282928
void uninitvar_malloc(void)
29292929
{
29302930
size_t size;
2931-
// cppcheck-suppress [uninitvar, cstyleCast]
2931+
// cppcheck-suppress [uninitvar, cstyleCast, unusedAllocatedMemory]
29322932
int *p = (int*)std::malloc(size);
29332933
free(p);
29342934
}
@@ -4957,7 +4957,7 @@ void std_vector_data_arithmetic()
49574957

49584958
void memleak_std_malloc() // #12332
49594959
{
4960-
//cppcheck-suppress [unreadVariable, constVariablePointer]
4960+
//cppcheck-suppress [unreadVariable, constVariablePointer, unusedAllocatedMemory]
49614961
void* p = std::malloc(1);
49624962
//cppcheck-suppress memleak
49634963
}
@@ -4971,7 +4971,7 @@ void memleak_std_realloc(void* block, size_t newsize)
49714971

49724972
void unusedAllocatedMemory_std_free()
49734973
{
4974-
// TODO cppcheck-suppress unusedAllocatedMemory
4974+
// cppcheck-suppress unusedAllocatedMemory
49754975
void* p = std::malloc(1);
49764976
std::free(p);
49774977
}

0 commit comments

Comments
 (0)