* Partial fix for #11137 FN: invalidFunctionArgStr printf argument * Typo * Remove <strz>, suppressions * Add suppresion, remove <strz> * Add suppressions
This commit is contained in:
parent
ff50a01d36
commit
5b9fa9657d
|
@ -5279,7 +5279,6 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s
|
||||||
<not-null/>
|
<not-null/>
|
||||||
<not-uninit/>
|
<not-uninit/>
|
||||||
<minsize type="argvalue" arg="2"/>
|
<minsize type="argvalue" arg="2"/>
|
||||||
<strz/>
|
|
||||||
</arg>
|
</arg>
|
||||||
<arg nr="2" direction="in">
|
<arg nr="2" direction="in">
|
||||||
<not-uninit/>
|
<not-uninit/>
|
||||||
|
|
|
@ -5209,7 +5209,6 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
|
||||||
<leak-ignore/>
|
<leak-ignore/>
|
||||||
<!-- In case the 3rd argument is 0, the 1st argument is permitted to be a null pointer. (#6306) -->
|
<!-- In case the 3rd argument is 0, the 1st argument is permitted to be a null pointer. (#6306) -->
|
||||||
<arg nr="1" direction="out">
|
<arg nr="1" direction="out">
|
||||||
<strz/>
|
|
||||||
<minsize type="argvalue" arg="3"/>
|
<minsize type="argvalue" arg="3"/>
|
||||||
</arg>
|
</arg>
|
||||||
<arg nr="2" direction="in">
|
<arg nr="2" direction="in">
|
||||||
|
|
|
@ -141,7 +141,7 @@ void CheckFunctions::invalidFunctionUsage()
|
||||||
const Variable* const variable = argtok->variable();
|
const Variable* const variable = argtok->variable();
|
||||||
// Is non-null terminated local variable of type char (e.g. char buf[] = {'x'};) ?
|
// Is non-null terminated local variable of type char (e.g. char buf[] = {'x'};) ?
|
||||||
if (variable && variable->isLocal()
|
if (variable && variable->isLocal()
|
||||||
&& valueType && valueType->type == ValueType::Type::CHAR) {
|
&& valueType && (valueType->type == ValueType::Type::CHAR || valueType->type == ValueType::Type::WCHAR_T)) {
|
||||||
const Token* varTok = variable->declEndToken();
|
const Token* varTok = variable->declEndToken();
|
||||||
auto count = -1; // Find out explicitly set count, e.g.: char buf[3] = {...}. Variable 'count' is set to 3 then.
|
auto count = -1; // Find out explicitly set count, e.g.: char buf[3] = {...}. Variable 'count' is set to 3 then.
|
||||||
if (varTok && Token::simpleMatch(varTok->previous(), "]"))
|
if (varTok && Token::simpleMatch(varTok->previous(), "]"))
|
||||||
|
@ -170,6 +170,13 @@ void CheckFunctions::invalidFunctionUsage()
|
||||||
&& (count == -1 || (count > 0 && count <= charsUntilFirstZero))) {
|
&& (count == -1 || (count > 0 && count <= charsUntilFirstZero))) {
|
||||||
invalidFunctionArgStrError(argtok, functionToken->str(), argnr);
|
invalidFunctionArgStrError(argtok, functionToken->str(), argnr);
|
||||||
}
|
}
|
||||||
|
} else if (count > -1 && Token::Match(varTok, "= %str%")) {
|
||||||
|
const Token* strTok = varTok->getValueTokenMinStrSize(mSettings);
|
||||||
|
if (strTok) {
|
||||||
|
const int strSize = Token::getStrArraySize(strTok);
|
||||||
|
if (strSize > count)
|
||||||
|
invalidFunctionArgStrError(argtok, functionToken->str(), argnr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -558,9 +558,7 @@ void bufferAccessOutOfBounds_bzero(void *s, size_t n)
|
||||||
size_t bufferAccessOutOfBounds_strnlen(const char *s, size_t maxlen)
|
size_t bufferAccessOutOfBounds_strnlen(const char *s, size_t maxlen)
|
||||||
{
|
{
|
||||||
const char buf[2]={'4','2'};
|
const char buf[2]={'4','2'};
|
||||||
// cppcheck-suppress invalidFunctionArgStr
|
|
||||||
size_t len = strnlen(buf,2);
|
size_t len = strnlen(buf,2);
|
||||||
// cppcheck-suppress invalidFunctionArgStr
|
|
||||||
// cppcheck-suppress bufferAccessOutOfBounds
|
// cppcheck-suppress bufferAccessOutOfBounds
|
||||||
len+=strnlen(buf,3);
|
len+=strnlen(buf,3);
|
||||||
return len;
|
return len;
|
||||||
|
|
|
@ -34,7 +34,7 @@ size_t invalidFunctionArgStr_wcslen(void)
|
||||||
const wchar_t terminated0[] = L"ABCDEF49620910";
|
const wchar_t terminated0[] = L"ABCDEF49620910";
|
||||||
const wchar_t terminated1[3] = { L'a', L'b', L'\0' };
|
const wchar_t terminated1[3] = { L'a', L'b', L'\0' };
|
||||||
const wchar_t notTerminated[3] = { L'a', L'b', L'c' };
|
const wchar_t notTerminated[3] = { L'a', L'b', L'c' };
|
||||||
// TODO: cppcheck-suppress invalidFunctionArgStr
|
// cppcheck-suppress invalidFunctionArgStr
|
||||||
(void) wcslen(notTerminated);
|
(void) wcslen(notTerminated);
|
||||||
(void) wcslen(terminated0);
|
(void) wcslen(terminated0);
|
||||||
return wcslen(terminated1);
|
return wcslen(terminated1);
|
||||||
|
@ -3908,10 +3908,11 @@ void bufferAccessOutOfBounds_strxfrm(void)
|
||||||
{
|
{
|
||||||
const char src[3] = "abc";
|
const char src[3] = "abc";
|
||||||
char dest[1] = "a";
|
char dest[1] = "a";
|
||||||
|
// cppcheck-suppress invalidFunctionArgStr
|
||||||
(void)strxfrm(dest,src,1);
|
(void)strxfrm(dest,src,1);
|
||||||
// cppcheck-suppress bufferAccessOutOfBounds
|
// cppcheck-suppress [bufferAccessOutOfBounds,invalidFunctionArgStr]
|
||||||
(void)strxfrm(dest,src,2);
|
(void)strxfrm(dest,src,2);
|
||||||
// cppcheck-suppress bufferAccessOutOfBounds
|
// cppcheck-suppress [bufferAccessOutOfBounds,invalidFunctionArgStr]
|
||||||
(void)strxfrm(dest,src,3);
|
(void)strxfrm(dest,src,3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -711,6 +711,18 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("int f() {\n"
|
||||||
|
" const char c[3] = \"abc\";\n"
|
||||||
|
" return strlen(c);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:3]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required.\n", errout.str());
|
||||||
|
|
||||||
|
check("int f() {\n"
|
||||||
|
" const wchar_t c[3] = L\"abc\";\n"
|
||||||
|
" return wcslen(c);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:3]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void mathfunctionCall_sqrt() {
|
void mathfunctionCall_sqrt() {
|
||||||
|
|
Loading…
Reference in New Issue