Fixed FP found with daca@home: ftp://ftp.de.debian.org/debian/pool/main/libs/libslirp/libslirp_4.7.0.orig.tar.bz2; head libslirp-v4.7.0/src/tftp.c:336:20: error: Invalid strcasecmp() argument nr 1. A nul-terminated string is required. [invalidFunctionArgStr]

This commit is contained in:
orbitcowboy 2022-06-04 12:00:54 +02:00
parent 3b133176ed
commit 433ce58fe6
2 changed files with 10 additions and 1 deletions

View File

@ -130,7 +130,7 @@ void CheckFunctions::invalidFunctionUsage()
if (Token::Match(argtok, "& %var% !![") && argtok->next() && argtok->next()->valueType()) {
const ValueType * valueType = argtok->next()->valueType();
const Variable * variable = argtok->next()->variable();
if ((valueType->type == ValueType::Type::CHAR || (valueType->type == ValueType::Type::RECORD && Token::Match(argtok, "& %var% . %var% !!."))) &&
if ((valueType->type == ValueType::Type::CHAR || (valueType->type == ValueType::Type::RECORD && Token::Match(argtok, "& %var% . %var% ,|)"))) &&
!variable->isArray() &&
(variable->isConst() || !variable->isGlobal()) &&
(!argtok->next()->hasKnownValue() || argtok->next()->getValue(0) == nullptr)) {

View File

@ -597,6 +597,15 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
check("struct someStruct {\n"
" char buf[42];\n"
"};\n"
"int f(struct someStruct * const tp, const int k)\n"
"{\n"
" return strcmp(&tp->buf[k], \"needle\");\n"
"}");
ASSERT_EQUALS("", errout.str());
check("const char x = 'x'; size_t f() { char y = x; return strlen(&y); }");
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required.\n", errout.str());