Improve check for wchar_t (#4285)

This commit is contained in:
chrchr-github 2022-07-16 23:46:10 +02:00 committed by GitHub
parent 109a031ec7
commit b16d12b5fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 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::WCHAR_T || (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

@ -745,6 +745,9 @@ private:
" s[strlen(s)] = ' ';\n" " s[strlen(s)] = ' ';\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("size_t f() { wchar_t x = L'x'; return wcslen(&x); }");
ASSERT_EQUALS("[test.cpp:1]: (error) Invalid wcslen() argument nr 1. A nul-terminated string is required.\n", errout.str());
} }
void mathfunctionCall_sqrt() { void mathfunctionCall_sqrt() {