From 9c0e6986dae91bf8f763c6f779ca0165181909d8 Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Sun, 8 Oct 2017 11:14:10 +0300 Subject: [PATCH] Passing string literals into printf as %p is fine --- lib/checkio.cpp | 2 +- test/testio.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/checkio.cpp b/lib/checkio.cpp index a67cc4e0a..cbea033aa 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -1275,7 +1275,7 @@ void CheckIO::checkFormatString(const Token * const tok, break; case 'p': if (argInfo.typeToken->tokType() == Token::eString) - invalidPrintfArgTypeError_p(tok, numFormat, &argInfo); + ;// string literals are passed as pointers to literal start, okay else if (argInfo.isKnownType() && !argInfo.isArrayOrPointer()) invalidPrintfArgTypeError_p(tok, numFormat, &argInfo); done = true; diff --git a/test/testio.cpp b/test/testio.cpp index 31846b55d..9e4b356c0 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -1575,6 +1575,17 @@ private: ASSERT_EQUALS("[test.cpp:3]: (warning) %p in format string (no. 1) requires an address but the argument type is 'foo'.\n" "[test.cpp:4]: (warning) %p in format string (no. 1) requires an address but the argument type is 'char'.\n", errout.str()); + check("class foo {};\n" + "void foo(char* pc, const char* cpc, wchar_t* pwc, const wchar_t* cpwc) {\n" + " printf(\"%p\", pc);\n" + " printf(\"%p\", cpc);\n" + " printf(\"%p\", pwc);\n" + " printf(\"%p\", cpwc);\n" + " printf(\"%p\", \"s4\");\n" + " printf(\"%p\", L\"s5W\");\n" + "}"); + ASSERT_EQUALS("", errout.str()); + check("class foo {};\n" "void foo(const int* cpi, foo f, bar b, bar* bp, double d) {\n" " printf(\"%e\", f);\n"