#7069 False positive invalidPrintfArgType_uint - %lu with 0ul

This commit is contained in:
Robert Reif 2016-02-19 10:12:47 +01:00 committed by amai2012
parent 648d492f94
commit 0fc59d0228
2 changed files with 11 additions and 4 deletions

View File

@ -1960,10 +1960,7 @@ void Tokenizer::simplifyNull()
else if (tok->str() == "__null" || tok->str() == "'\\0'" || tok->str() == "'\\x0'") { else if (tok->str() == "__null" || tok->str() == "'\\0'" || tok->str() == "'\\x0'") {
tok->originalName(tok->str()); tok->originalName(tok->str());
tok->str("0"); tok->str("0");
} else if (tok->isNumber() && }
MathLib::isInt(tok->str()) &&
MathLib::toLongNumber(tok->str()) == 0)
tok->str("0");
} }
// nullptr.. // nullptr..

View File

@ -60,6 +60,7 @@ private:
TEST_CASE(testUnsignedConst); // ticket #6132 TEST_CASE(testUnsignedConst); // ticket #6132
TEST_CASE(testAstType); // #7014 TEST_CASE(testAstType); // #7014
TEST_CASE(testPrintf0WithSuffix); // ticket #7069
} }
void check(const char code[], bool inconclusive = false, bool portability = false, Settings::PlatformType platform = Settings::Unspecified) { void check(const char code[], bool inconclusive = false, bool portability = false, Settings::PlatformType platform = Settings::Unspecified) {
@ -2765,6 +2766,15 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:2]: (warning) %i in format string (no. 1) requires 'int' but the argument type is 'signed short *'.\n", errout.str()); ASSERT_EQUALS("[test.cpp:2]: (warning) %i in format string (no. 1) requires 'int' but the argument type is 'signed short *'.\n", errout.str());
} }
void testPrintf0WithSuffix() { // ticket #7069
check("void foo() {\n"
" printf(\"%u %lu %llu\", 0U, 0UL, 0ULL);\n"
" printf(\"%u %lu %llu\", 0u, 0ul, 0ull);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
}; };
REGISTER_TEST(TestIO) REGISTER_TEST(TestIO)