Fix false positive: Invalid string argument with pointer to pointer (#1427)
If the address is taken inside an array, the address is not of a single character, so do not warn about this.
This commit is contained in:
parent
290563b964
commit
f1074ea1ab
|
@ -127,7 +127,7 @@ void CheckFunctions::invalidFunctionUsage()
|
|||
}
|
||||
|
||||
if (mSettings->library.isargstrz(functionToken, argnr)) {
|
||||
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 Variable * variable = argtok->next()->variable();
|
||||
if (valueType->type == ValueType::Type::CHAR && !variable->isGlobal() &&
|
||||
|
|
|
@ -502,6 +502,9 @@ private:
|
|||
check("size_t f() { char x[] = \"Hello world\"; return strlen(&x[0]) }");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("size_t f() { char* x = \"Hello world\"; return strlen(&x[0]) }");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("struct S {\n"
|
||||
" char x;\n"
|
||||
"};\n"
|
||||
|
@ -527,6 +530,13 @@ private:
|
|||
check("const char x = '\\0'; size_t f() { char y = x; return strlen(&y); }");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("size_t f() {\n"
|
||||
" char * a = \"Hello world\";\n"
|
||||
" char ** b = &a;\n"
|
||||
" return strlen(&b[0][0]);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #5225
|
||||
check("int main(void)\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue