Fix #8557 FP format string requires unsigned long (for sizeof(var)) (#3727)

This commit is contained in:
chrchr-github 2022-01-27 19:43:52 +01:00 committed by GitHub
parent 171da2e6f9
commit f429245da2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -6553,8 +6553,10 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
}
else if (Token::simpleMatch(tok->previous(), "sizeof (")) {
// TODO: use specified size_t type
ValueType valuetype(ValueType::Sign::UNSIGNED, ValueType::Type::LONG, 0U);
if (mSettings->platformType == cppcheck::Platform::Win64)
valuetype.type = ValueType::Type::LONGLONG;
valuetype.originalTypeName = "size_t";
setValueType(tok, valuetype);

View File

@ -3300,6 +3300,12 @@ private:
" printf(\"%f\", x.f(4.0));\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" printf(\"%lu\", sizeof(char));\n"
"}\n", false, true, Settings::Win64);
ASSERT_EQUALS("[test.cpp:2]: (portability) %lu in format string (no. 1) requires 'unsigned long' but the argument type is 'size_t {aka unsigned long long}'.\n",
errout.str());
}
void testPrintfArgumentVariables() {