From f429245da2182fde262c4ccd1710f334f2cb7811 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 27 Jan 2022 19:43:52 +0100 Subject: [PATCH] Fix #8557 FP format string requires unsigned long (for sizeof(var)) (#3727) --- lib/symboldatabase.cpp | 4 +++- test/testio.cpp | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index a5c0cd773..a3d3e7c72 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -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); diff --git a/test/testio.cpp b/test/testio.cpp index abd4928f9..187bb30f4 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -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() {