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 07:46:28 +02:00
parent 9e8d5d1b2e
commit 1c1c72058f
2 changed files with 16 additions and 1 deletions

View File

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

View File

@ -582,6 +582,21 @@ private:
check("const char x = 'x'; size_t f() { return strlen(&x); }"); check("const char x = 'x'; size_t f() { return strlen(&x); }");
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required.\n", errout.str()); ASSERT_EQUALS("[test.cpp:1]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required.\n", errout.str());
check("struct someStruct {\n"
" union {\n"
" struct {\n"
" uint16_t nr;\n"
" uint8_t d[40];\n"
" } data;\n"
" char buf[42];\n"
" } x;\n"
"};\n"
"int f(struct someStruct * const tp, const int k)\n"
"{\n"
" return strcmp(&tp->x.buf[k], \"needle\");\n"
"}");
ASSERT_EQUALS("", errout.str());
check("const char x = 'x'; size_t f() { char y = x; return strlen(&y); }"); 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()); ASSERT_EQUALS("[test.cpp:1]: (error) Invalid strlen() argument nr 1. A nul-terminated string is required.\n", errout.str());