Skip to content

Commit 7325154

Browse files
Fix #11842 FN constParameterPointer with library function (#5257)
1 parent 77c479a commit 7325154

24 files changed

Lines changed: 440 additions & 419 deletions

cfg/posix.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3362,7 +3362,7 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s
33623362
<use-retval/>
33633363
<returnValue type="int"/>
33643364
<noreturn>false</noreturn>
3365-
<arg nr="1" direction="in">
3365+
<arg nr="1">
33663366
<not-null/>
33673367
<not-uninit/>
33683368
</arg>

cfg/qt.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,11 +444,12 @@
444444
<!-- QAction *QMenu::addAction(const QIcon &icon, const QString &text, const QObject *receiver, PointerToMemberFunction method, const QKeySequence &shortcut = ...) -->
445445
<!-- QAction *QMenu::addAction(const QIcon &icon, const QString &text, Functor functor, const QKeySequence &shortcut = ...) -->
446446
<!-- QAction *QMenu::addAction(const QIcon &icon, const QString &text, const QObject *context, Functor functor, const QKeySequence &shortcut = 0) -->
447+
<!-- void QWidget::addAction(QAction *action) -->
447448
<function name="QMenu::addAction">
448449
<noreturn>false</noreturn>
449450
<returnValue type="QAction *"/>
450451
<leak-ignore/>
451-
<arg nr="1" direction="in">
452+
<arg nr="1">
452453
<not-uninit/>
453454
<not-bool/>
454455
</arg>

cfg/std.cfg

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,7 +1584,7 @@
15841584
<returnValue type="int"/>
15851585
<noreturn>false</noreturn>
15861586
<leak-ignore/>
1587-
<arg nr="1" direction="in">
1587+
<arg nr="1">
15881588
<not-null/>
15891589
<not-uninit/>
15901590
</arg>
@@ -1595,7 +1595,7 @@
15951595
<returnValue type="int"/>
15961596
<noreturn>false</noreturn>
15971597
<leak-ignore/>
1598-
<arg nr="1" direction="in">
1598+
<arg nr="1">
15991599
<not-null/>
16001600
<not-uninit/>
16011601
</arg>
@@ -2290,7 +2290,7 @@
22902290
<returnValue type="int"/>
22912291
<noreturn>false</noreturn>
22922292
<leak-ignore/>
2293-
<arg nr="1" direction="in">
2293+
<arg nr="1">
22942294
<not-null/>
22952295
<not-uninit/>
22962296
</arg>
@@ -3815,7 +3815,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
38153815
<returnValue type="void *"/>
38163816
<noreturn>false</noreturn>
38173817
<leak-ignore/>
3818-
<arg nr="1" direction="in">
3818+
<arg nr="1">
38193819
<not-null/>
38203820
<not-uninit/>
38213821
<minsize type="argvalue" arg="3"/>
@@ -3838,7 +3838,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
38383838
<returnValue type="wchar_t *"/>
38393839
<noreturn>false</noreturn>
38403840
<leak-ignore/>
3841-
<arg nr="1" direction="in">
3841+
<arg nr="1">
38423842
<not-null/>
38433843
<not-uninit/>
38443844
<minsize type="argvalue" arg="3"/>
@@ -4851,7 +4851,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
48514851
<valid>0:255</valid>
48524852
</arg>
48534853
</function>
4854-
<!-- wchar_t wcschr(const wchar_t *cs, wchar_t c); -->
4854+
<!-- wchar_t* wcschr(const wchar_t *cs, wchar_t c); -->
48554855
<function name="wcschr,std::wcschr">
48564856
<use-retval/>
48574857
<returnValue type="wchar_t"/>
@@ -5154,7 +5154,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
51545154
<returnValue type="char *"/>
51555155
<noreturn>false</noreturn>
51565156
<leak-ignore/>
5157-
<arg nr="1" direction="in">
5157+
<arg nr="1">
51585158
<not-null/>
51595159
<not-uninit/>
51605160
<strz/>
@@ -5172,7 +5172,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
51725172
<returnValue type="wchar_t *"/>
51735173
<noreturn>false</noreturn>
51745174
<leak-ignore/>
5175-
<arg nr="1" direction="in">
5175+
<arg nr="1">
51765176
<not-null/>
51775177
<not-uninit/>
51785178
<strz/>
@@ -5429,7 +5429,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
54295429
<returnValue type="wchar_t *"/>
54305430
<noreturn>false</noreturn>
54315431
<leak-ignore/>
5432-
<arg nr="1" direction="in">
5432+
<arg nr="1">
54335433
<not-null/>
54345434
<not-uninit/>
54355435
<strz/>
@@ -8263,7 +8263,7 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init
82638263
<noreturn>false</noreturn>
82648264
<returnValue type="void"/>
82658265
<leak-ignore/>
8266-
<arg nr="1" direction="in">
8266+
<arg nr="1">
82678267
<not-null/>
82688268
<not-uninit/>
82698269
<not-bool/>
@@ -8274,7 +8274,7 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init
82748274
<noreturn>false</noreturn>
82758275
<returnValue type="char *"/>
82768276
<use-retval/>
8277-
<arg nr="1">
8277+
<arg nr="1" direction="in">
82788278
<not-null/>
82798279
<not-uninit/>
82808280
<not-bool/>

cfg/windows.cfg

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,7 +1749,7 @@
17491749
<function name="CloseHandle">
17501750
<noreturn>false</noreturn>
17511751
<returnValue type="BOOL"/>
1752-
<arg nr="1" direction="in">
1752+
<arg nr="1">
17531753
<not-uninit/>
17541754
</arg>
17551755
</function>
@@ -3901,7 +3901,7 @@ HFONT CreateFont(
39013901
<not-uninit/>
39023902
<not-null/>
39033903
</arg>
3904-
<arg nr="4" direction="in">
3904+
<arg nr="4">
39053905
<not-uninit/>
39063906
</arg>
39073907
<arg nr="5" direction="in">
@@ -4772,7 +4772,7 @@ HFONT CreateFont(
47724772
<function name="FreeLibrary">
47734773
<noreturn>false</noreturn>
47744774
<returnValue type="BOOL"/>
4775-
<arg nr="1" direction="in">
4775+
<arg nr="1">
47764776
<not-uninit/>
47774777
<not-bool/>
47784778
</arg>
@@ -4884,7 +4884,7 @@ HFONT CreateFont(
48844884
<returnValue type="FARPROC"/>
48854885
<use-retval/>
48864886
<leak-ignore/>
4887-
<arg nr="1" direction="in">
4887+
<arg nr="1">
48884888
<not-uninit/>
48894889
<not-bool/>
48904890
<not-null/>
@@ -4971,7 +4971,7 @@ HFONT CreateFont(
49714971
<noreturn>false</noreturn>
49724972
<returnValue type="BOOL"/>
49734973
<leak-ignore/>
4974-
<arg nr="1" direction="in">
4974+
<arg nr="1">
49754975
<not-null/>
49764976
<not-uninit/>
49774977
</arg>
@@ -5364,7 +5364,7 @@ HFONT CreateFont(
53645364
<returnValue type="BOOL"/>
53655365
<noreturn>false</noreturn>
53665366
<leak-ignore/>
5367-
<arg nr="1" direction="in">
5367+
<arg nr="1">
53685368
<not-uninit/>
53695369
<not-bool/>
53705370
</arg>
@@ -6324,7 +6324,7 @@ HFONT CreateFont(
63246324
<function name="LocalFree">
63256325
<noreturn>false</noreturn>
63266326
<returnValue type="HLOCAL"/>
6327-
<arg nr="1" direction="in">
6327+
<arg nr="1">
63286328
<not-bool/>
63296329
</arg>
63306330
</function>

cfg/wxwidgets.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6820,7 +6820,7 @@
68206820
<noreturn>false</noreturn>
68216821
<leak-ignore/>
68226822
<returnValue type="wxSizerItem*"/>
6823-
<arg nr="1" direction="in">
6823+
<arg nr="1">
68246824
<!-- <not-null/> Deactivated due to FPs with overloaded function: wxSizerItem * Add (int width, int height, int proportion=0, int flag=0, int border=0, wxObject *userData=NULL) -->
68256825
<not-uninit/>
68266826
</arg>
@@ -7309,7 +7309,7 @@
73097309
<noreturn>false</noreturn>
73107310
<leak-ignore/>
73117311
<returnValue type="void"/>
7312-
<arg nr="1" direction="in">
7312+
<arg nr="1">
73137313
<not-null/>
73147314
<not-uninit/>
73157315
</arg>

gui/codeeditor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ CodeEditor::CodeEditor(QWidget *parent) :
290290
QShortcut *copyText = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_C),this);
291291
QShortcut *allText = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_A),this);
292292
#else
293-
QShortcut *copyText = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_C),this);
294-
QShortcut *allText = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_A),this);
293+
const QShortcut *copyText = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_C),this);
294+
const QShortcut *allText = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_A),this);
295295
#endif
296296

297297
connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));

gui/resultstree.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
723723
mContextItem = mModel.itemFromIndex(index);
724724
if (mContextItem && mApplications->getApplicationCount() > 0 && mContextItem->parent()) {
725725
//Disconnect all signals
726-
for (QAction* action : actions) {
726+
for (const QAction* action : actions) {
727727
disconnect(action, SIGNAL(triggered()), signalMapper, SLOT(map()));
728728
}
729729

lib/checkother.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,13 +1645,20 @@ void CheckOther::checkConstPointer()
16451645
if (Token::simpleMatch(parent, "=") && parent->astOperand1() == tok)
16461646
continue;
16471647
if (const Token* ftok = getTokenArgumentFunction(tok, argn)) {
1648-
if (ftok->function() && !parent->isCast()) {
1649-
const Variable* argVar = ftok->function()->getArgumentVar(argn);
1650-
if (argVar && argVar->valueType() && argVar->valueType()->isConst(vt->pointer)) {
1651-
bool inconclusive{};
1652-
if (!isVariableChangedByFunctionCall(ftok, vt->pointer, var->declarationId(), mSettings, &inconclusive) && !inconclusive)
1653-
continue;
1648+
if (ftok->function()) {
1649+
const bool isCastArg = parent->isCast() && !ftok->function()->getOverloadedFunctions().empty(); // assume that cast changes the called function
1650+
if (!isCastArg) {
1651+
const Variable* argVar = ftok->function()->getArgumentVar(argn);
1652+
if (argVar && argVar->valueType() && argVar->valueType()->isConst(vt->pointer)) {
1653+
bool inconclusive{};
1654+
if (!isVariableChangedByFunctionCall(ftok, vt->pointer, var->declarationId(), mSettings, &inconclusive) && !inconclusive)
1655+
continue;
1656+
}
16541657
}
1658+
} else {
1659+
const auto dir = mSettings->library.getArgDirection(ftok, argn + 1);
1660+
if (dir == Library::ArgumentChecks::Direction::DIR_IN)
1661+
continue;
16551662
}
16561663
}
16571664
else if (Token::simpleMatch(parent, "(")) {

lib/symboldatabase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4362,7 +4362,7 @@ std::vector<const Function*> Function::getOverloadedFunctions() const
43624362
it != scope->functionMap.end() && it->first == tokenDef->str();
43634363
++it) {
43644364
const Function* func = it->second;
4365-
if (isMemberFunction == func->isStatic())
4365+
if (isMemberFunction && isMemberFunction == func->isStatic())
43664366
continue;
43674367
result.push_back(func);
43684368
}

test/cfg/gnu.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void unreachableCode_error(void) // #11197
3939
}
4040
#endif
4141

42-
int nullPointer_gethostbyname2_r(const char* name, int af, struct hostent* ret, char* buf, size_t buflen, struct hostent** result, int* h_errnop)
42+
int nullPointer_gethostbyname2_r(const char* name, int af, struct hostent* ret, const char* buf, size_t buflen, struct hostent** result, const int* h_errnop)
4343
{
4444
// cppcheck-suppress nullPointer
4545
(void) gethostbyname2_r(NULL, af, ret, buf, buflen, result, h_errnop);
@@ -54,7 +54,7 @@ int nullPointer_gethostbyname2_r(const char* name, int af, struct hostent* ret,
5454
return gethostbyname2_r(name, af, ret, buf, buflen, result, h_errnop);
5555
}
5656

57-
int nullPointer_gethostbyname_r(const char* name, struct hostent* ret, char* buf, size_t buflen, struct hostent** result, int* h_errnop)
57+
int nullPointer_gethostbyname_r(const char* name, struct hostent* ret, const char* buf, size_t buflen, struct hostent** result, const int* h_errnop)
5858
{
5959
// cppcheck-suppress nullPointer
6060
(void) gethostbyname_r(NULL, ret, buf, buflen, result, h_errnop);
@@ -70,7 +70,7 @@ int nullPointer_gethostbyname_r(const char* name, struct hostent* ret, char* buf
7070
}
7171

7272

73-
int nullPointer_gethostbyaddr_r(const void* addr, socklen_t len, int type, struct hostent* ret, char* buf, size_t buflen, struct hostent** result, int* h_errnop)
73+
int nullPointer_gethostbyaddr_r(const void* addr, socklen_t len, int type, struct hostent* ret, const char* buf, size_t buflen, struct hostent** result, const int* h_errnop)
7474
{
7575
// cppcheck-suppress nullPointer
7676
(void) gethostbyaddr_r(NULL, len, type, ret, buf, buflen, result, h_errnop);
@@ -109,7 +109,7 @@ int nullPointer_getopt_long_only(int argc, char* const* argv, const char* optstr
109109
return getopt_long_only(argc, argv, optstring, longopts, longindex);
110110
}
111111

112-
int nullPointer_getservent_r(struct servent *restrict result_buf, char *restrict buf, size_t buflen, struct servent **restrict result)
112+
int nullPointer_getservent_r(struct servent *restrict result_buf, const char *restrict buf, size_t buflen, struct servent **restrict result)
113113
{
114114
// cppcheck-suppress nullPointer
115115
(void) getservent_r(NULL, buf, buflen, result);
@@ -122,7 +122,7 @@ int nullPointer_getservent_r(struct servent *restrict result_buf, char *restrict
122122

123123
void *bufferAccessOutOfBounds_memrchr(const void *s, int c, size_t n)
124124
{
125-
char buf[42]={0};
125+
const char buf[42]={0};
126126
(void)memrchr(buf,c,42);
127127
// cppcheck-suppress bufferAccessOutOfBounds
128128
(void)memrchr(buf,c,43);
@@ -275,17 +275,17 @@ int no_resourceLeak_mkostemp_02(char *template, int flags)
275275
return mkostemp(template, flags);
276276
}
277277

278-
void valid_code(int argInt1, va_list valist_arg, int * parg)
278+
void valid_code(int argInt1, va_list valist_arg, const int * parg)
279279
{
280280
char *p;
281281

282282
if (__builtin_expect(argInt1, 0)) {}
283283
if (__builtin_expect_with_probability(argInt1 + 1, 2, 0.5)) {}
284284
if (__glibc_unlikely(argInt1 != 0)) {}
285285
if (__glibc_likely(parg != NULL)) {}
286-
void *ax1 = __builtin_assume_aligned(parg, 16);
286+
const void *ax1 = __builtin_assume_aligned(parg, 16);
287287
printf("%p", ax1);
288-
void *ax2 = __builtin_assume_aligned(parg, 32, 8);
288+
const void *ax2 = __builtin_assume_aligned(parg, 32, 8);
289289
printf("%p", ax2);
290290

291291
p = (char *)malloc(10);
@@ -316,7 +316,7 @@ void valid_code(int argInt1, va_list valist_arg, int * parg)
316316

317317
if (__alignof__(int) == 4) {}
318318

319-
void * p_mmap = mmap(NULL, 1, PROT_NONE, MAP_ANONYMOUS | MAP_SHARED, -1, 0);
319+
const void * p_mmap = mmap(NULL, 1, PROT_NONE, MAP_ANONYMOUS | MAP_SHARED, -1, 0);
320320
printf("%p", p_mmap);
321321
munmap(p_mmap, 1);
322322

@@ -368,7 +368,7 @@ void memleak_xmalloc()
368368

369369
void memleak_mmap()
370370
{
371-
void * p_mmap = mmap(NULL, 1, PROT_NONE, MAP_ANONYMOUS | MAP_SHARED, -1, 0);
371+
const void * p_mmap = mmap(NULL, 1, PROT_NONE, MAP_ANONYMOUS | MAP_SHARED, -1, 0);
372372
printf("%p", p_mmap);
373373
// cppcheck-suppress memleak
374374
}
@@ -391,7 +391,7 @@ void bufferAccessOutOfBounds__builtin_memset(void)
391391

392392
void bufferAccessOutOfBounds()
393393
{
394-
char buf[2] = "a";
394+
const char buf[2] = "a";
395395
// This is valid
396396
sethostname(buf, 2);
397397
// cppcheck-suppress bufferAccessOutOfBounds

0 commit comments

Comments
 (0)