Skip to content

Commit 167421b

Browse files
committed
Fix
1 parent 1fa524a commit 167421b

5 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎cfg/gtk.cfg‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5386,11 +5386,13 @@
53865386
<arg nr="1" direction="in">
53875387
<not-null/>
53885388
<not-uninit/>
5389+
<strz/>
53895390
<minsize type="argvalue" arg="3"/>
53905391
</arg>
53915392
<arg nr="2" direction="in">
53925393
<not-null/>
53935394
<not-uninit/>
5395+
<strz/>
53945396
<minsize type="argvalue" arg="3"/>
53955397
</arg>
53965398
<arg nr="3" direction="in">

‎cfg/posix.cfg‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5608,6 +5608,7 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s
56085608
<arg nr="1" direction="in">
56095609
<not-null/>
56105610
<not-uninit/>
5611+
<strz/>
56115612
<minsize type="argvalue" arg="2"/>
56125613
</arg>
56135614
<arg nr="2" direction="in">
@@ -5784,6 +5785,7 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s
57845785
<arg nr="2" direction="in">
57855786
<not-null/>
57865787
<not-uninit/>
5788+
<strz/>
57875789
<minsize type="argvalue" arg="3"/>
57885790
</arg>
57895791
<arg nr="3" direction="in">

‎cfg/windows.cfg‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4293,11 +4293,13 @@ HFONT CreateFont(
42934293
<arg nr="1" direction="in">
42944294
<not-null/>
42954295
<not-uninit/>
4296+
<strz/>
42964297
<minsize type="argvalue" arg="3"/>
42974298
</arg>
42984299
<arg nr="2" direction="in">
42994300
<not-null/>
43004301
<not-uninit/>
4302+
<strz/>
43014303
<minsize type="argvalue" arg="3"/>
43024304
</arg>
43034305
<arg nr="3" direction="in">

‎lib/checkfunctions.cpp‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ void CheckFunctionsImpl::functionCalledError(const Token* tok, Severity severity
102102
reportError(tok, severity, prefix + "Called", msg, CWE477, Certainty::normal);
103103
}
104104

105+
static bool hasMinSize(const Token* ftok, int argnr, const Settings& settings)
106+
{
107+
const auto minsizes = settings.library.argminsizes(ftok, argnr);
108+
return minsizes && !minsizes->empty();
109+
}
110+
105111
//---------------------------------------------------------------------------
106112
// Check <valid>, <strz> and <not-bool>
107113
//---------------------------------------------------------------------------
@@ -137,7 +143,7 @@ void CheckFunctionsImpl::invalidFunctionUsage()
137143
invalidFunctionArgError(argtok, functionToken->str(), argnr, nullptr, mSettings.library.validarg(functionToken, argnr));
138144
}
139145
// check <strz>
140-
if (mSettings.library.isargstrz(functionToken, argnr)) {
146+
if (mSettings.library.isargstrz(functionToken, argnr) && !hasMinSize(functionToken, argnr, mSettings)) {
141147
if (Token::Match(argtok, "& %var% !![") && argtok->next() && argtok->next()->valueType()) {
142148
const ValueType * valueType = argtok->next()->valueType();
143149
const Variable * variable = argtok->next()->variable();

‎test/cfg/posix.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ void invalidFunctionArgStr_mbsnrtowcs(void)
194194
if (mbsnrtowcs (wenough, &cp, 1, 10, &s) != 1 || wcscmp (wenough, L"AEF") != 0) {}
195195
}
196196

197+
int invalidFunctionArgStr_strncasecmp(const char* s)
198+
{
199+
const char buf[3] = {'a', 'b', 'c'};
200+
return strncasecmp(buf, s, 3);
201+
}
202+
197203
struct tm * ignoredReturnValue_localtime(const time_t *tp)
198204
{
199205
// cppcheck-suppress [ignoredReturnValue,localtimeCalled]
@@ -719,7 +725,7 @@ size_t bufferAccessOutOfBounds_strnlen(const char *s, size_t maxlen)
719725
size_t len = strnlen(buf,2);
720726
// cppcheck-suppress bufferAccessOutOfBounds
721727
len+=strnlen(buf,3);
722-
len+=strnlen("ab",3);
728+
len+=strnlen("ab",5);
723729
return len;
724730
}
725731

0 commit comments

Comments
 (0)