Fix #7038 false negative for string argument in the CheckIO (#3649)

This commit is contained in:
chrchr-github 2021-12-20 17:22:39 +01:00 committed by GitHub
parent e6091cbe54
commit ca4e5ac527
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -1386,6 +1386,8 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * arg, const Settings *settings,
for (int p = 0; p < valuetype->pointer; p++)
tempToken->insertToken("*");
tempToken = const_cast<Token*>(typeToken);
if (top->isBinaryOp() && valuetype->pointer == 1 && (valuetype->type == ValueType::CHAR || valuetype->type == ValueType::WCHAR_T))
tempToken->tokType(Token::eString);
return;
}
}

View File

@ -2113,6 +2113,11 @@ private:
ASSERT_EQUALS("[test.cpp:3]: (warning) %s in format string (no. 1) requires a 'char *' but the argument type is 'const char *'.\n"
"[test.cpp:3]: (warning) scanf() without field width limits can crash with huge input data.\n", errout.str());
}
check("void f() {\n" // #7038
" scanf(\"%i\", \"abc\" + 1);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2]: (warning) %i in format string (no. 1) requires 'int *' but the argument type is 'const char *'.\n", errout.str());
}
void testPrintfArgument() {