Passing string literals into printf as %p is fine
This commit is contained in:
parent
be2c65eb58
commit
9c0e6986da
|
@ -1275,7 +1275,7 @@ void CheckIO::checkFormatString(const Token * const tok,
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
if (argInfo.typeToken->tokType() == Token::eString)
|
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())
|
else if (argInfo.isKnownType() && !argInfo.isArrayOrPointer())
|
||||||
invalidPrintfArgTypeError_p(tok, numFormat, &argInfo);
|
invalidPrintfArgTypeError_p(tok, numFormat, &argInfo);
|
||||||
done = true;
|
done = true;
|
||||||
|
|
|
@ -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"
|
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());
|
"[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"
|
check("class foo {};\n"
|
||||||
"void foo(const int* cpi, foo f, bar b, bar* bp, double d) {\n"
|
"void foo(const int* cpi, foo f, bar b, bar* bp, double d) {\n"
|
||||||
" printf(\"%e\", f);\n"
|
" printf(\"%e\", f);\n"
|
||||||
|
|
Loading…
Reference in New Issue