Skip to content

Commit f429245

Browse files
Fix #8557 FP format string requires unsigned long (for sizeof(var)) (#3727)
1 parent 171da2e commit f429245

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

lib/symboldatabase.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6553,8 +6553,10 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
65536553
}
65546554

65556555
else if (Token::simpleMatch(tok->previous(), "sizeof (")) {
6556-
// TODO: use specified size_t type
65576556
ValueType valuetype(ValueType::Sign::UNSIGNED, ValueType::Type::LONG, 0U);
6557+
if (mSettings->platformType == cppcheck::Platform::Win64)
6558+
valuetype.type = ValueType::Type::LONGLONG;
6559+
65586560
valuetype.originalTypeName = "size_t";
65596561
setValueType(tok, valuetype);
65606562

test/testio.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3300,6 +3300,12 @@ class TestIO : public TestFixture {
33003300
" printf(\"%f\", x.f(4.0));\n"
33013301
"}");
33023302
ASSERT_EQUALS("", errout.str());
3303+
3304+
check("void f() {\n"
3305+
" printf(\"%lu\", sizeof(char));\n"
3306+
"}\n", false, true, Settings::Win64);
3307+
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",
3308+
errout.str());
33033309
}
33043310

33053311
void testPrintfArgumentVariables() {

0 commit comments

Comments
 (0)