2012-05-20 21:26:48 +02:00
/*
* Cppcheck - A tool for static C / C + + code analysis
2023-01-28 10:16:34 +01:00
* Copyright ( C ) 2007 - 2023 Cppcheck team .
2012-05-20 21:26:48 +02:00
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
2017-05-27 04:33:47 +02:00
2012-05-20 21:26:48 +02:00
# include "checkio.h"
2022-01-27 19:03:20 +01:00
# include "config.h"
# include "errortypes.h"
2017-05-27 04:33:47 +02:00
# include "platform.h"
# include "settings.h"
2023-01-27 08:18:32 +01:00
# include "fixture.h"
2012-05-20 21:26:48 +02:00
# include "tokenize.h"
2017-03-08 15:16:19 +01:00
2022-09-16 07:15:49 +02:00
# include <sstream> // IWYU pragma: keep
2023-03-04 08:53:19 +01:00
# include <string>
2022-01-27 19:03:20 +01:00
2012-05-20 21:26:48 +02:00
class TestIO : public TestFixture {
public :
2021-08-07 20:51:18 +02:00
TestIO ( ) : TestFixture ( " TestIO " ) { }
2012-05-20 21:26:48 +02:00
private :
2023-05-02 11:48:24 +02:00
const Settings settings = settingsBuilder ( ) . library ( " std.cfg " ) . library ( " windows.cfg " ) . library ( " qt.cfg " ) . build ( ) ;
Settings settings1 = settingsBuilder ( ) . library ( " std.cfg " ) . library ( " windows.cfg " ) . library ( " qt.cfg " ) . build ( ) ;
2012-05-20 21:26:48 +02:00
2022-02-10 23:02:24 +01:00
void run ( ) override {
2012-05-20 21:26:48 +02:00
TEST_CASE ( coutCerrMisusage ) ;
2012-05-22 14:30:22 +02:00
TEST_CASE ( wrongMode_simple ) ;
TEST_CASE ( wrongMode_complex ) ;
TEST_CASE ( useClosedFile ) ;
TEST_CASE ( fileIOwithoutPositioning ) ;
2014-03-17 11:02:03 +01:00
TEST_CASE ( seekOnAppendedFile ) ;
2012-05-22 14:30:22 +02:00
TEST_CASE ( fflushOnInputStream ) ;
2021-07-10 13:59:47 +02:00
TEST_CASE ( incompatibleFileOpen ) ;
2012-05-20 21:26:48 +02:00
TEST_CASE ( testScanf1 ) ; // Scanf without field limiters
TEST_CASE ( testScanf2 ) ;
2016-05-22 14:00:26 +02:00
TEST_CASE ( testScanf3 ) ; // #3494
2012-07-24 15:54:38 +02:00
TEST_CASE ( testScanf4 ) ; // #ticket 2553
2021-12-01 09:51:48 +01:00
TEST_CASE ( testScanf5 ) ; // #10632
2012-05-20 21:26:48 +02:00
TEST_CASE ( testScanfArgument ) ;
TEST_CASE ( testPrintfArgument ) ;
2017-11-10 21:53:53 +01:00
TEST_CASE ( testPrintfArgumentVariables ) ;
2013-07-28 15:00:28 +02:00
TEST_CASE ( testPosixPrintfScanfParameterPosition ) ; // #4900
2013-07-21 08:35:01 +02:00
TEST_CASE ( testMicrosoftPrintfArgument ) ; // ticket #4902
2013-10-03 06:37:40 +02:00
TEST_CASE ( testMicrosoftScanfArgument ) ;
2013-09-26 16:20:01 +02:00
TEST_CASE ( testMicrosoftCStringFormatArguments ) ; // ticket #4920
2013-09-30 19:55:21 +02:00
TEST_CASE ( testMicrosoftSecurePrintfArgument ) ;
TEST_CASE ( testMicrosoftSecureScanfArgument ) ;
2014-09-24 16:45:06 +02:00
2016-08-20 08:47:52 +02:00
TEST_CASE ( testQStringFormatArguments ) ;
2014-09-24 16:45:06 +02:00
TEST_CASE ( testTernary ) ; // ticket #6182
2014-12-27 10:53:26 +01:00
TEST_CASE ( testUnsignedConst ) ; // ticket #6132
2015-10-05 10:12:30 +02:00
TEST_CASE ( testAstType ) ; // #7014
2016-02-19 10:12:47 +01:00
TEST_CASE ( testPrintf0WithSuffix ) ; // ticket #7069
2017-10-03 22:10:13 +02:00
TEST_CASE ( testReturnValueTypeStdLib ) ;
2018-01-12 08:19:21 +01:00
TEST_CASE ( testPrintfTypeAlias1 ) ;
2019-02-27 06:44:31 +01:00
TEST_CASE ( testPrintfAuto ) ; // #8992
2020-01-27 06:55:01 +01:00
TEST_CASE ( testPrintfParenthesis ) ; // #8489
2021-06-24 23:19:29 +02:00
TEST_CASE ( testStdDistance ) ; // #10304
2022-12-15 08:52:13 +01:00
TEST_CASE ( testParameterPack ) ; // #11289
2012-05-20 21:26:48 +02:00
}
2021-11-29 07:34:39 +01:00
# define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
2023-03-03 18:36:27 +01:00
void check_ ( const char * file , int line , const char * code , bool inconclusive = false , bool portability = false , cppcheck : : Platform : : Type platform = cppcheck : : Platform : : Type : : Unspecified , bool onlyFormatStr = false , bool cpp = true ) {
2012-05-20 21:26:48 +02:00
// Clear the error buffer..
errout . str ( " " ) ;
2023-05-02 15:54:19 +02:00
// TODO: using dedicated Settings (i.e. copying it) object causes major slowdown
2023-05-02 11:48:24 +02:00
settings1 . severity . clear ( ) ;
settings1 . severity . enable ( Severity : : warning ) ;
settings1 . severity . enable ( Severity : : style ) ;
2012-07-07 13:34:37 +02:00
if ( portability )
2023-05-02 11:48:24 +02:00
settings1 . severity . enable ( Severity : : portability ) ;
settings1 . certainty . setEnabled ( Certainty : : inconclusive , inconclusive ) ;
PLATFORM ( settings1 . platform , platform ) ;
2012-05-20 21:26:48 +02:00
// Tokenize..
2023-05-02 11:48:24 +02:00
Tokenizer tokenizer ( & settings1 , this ) ;
2012-05-20 21:26:48 +02:00
std : : istringstream istr ( code ) ;
2023-02-23 22:53:39 +01:00
const std : : string file_in = cpp ? " test.cpp " : " test.c " ;
ASSERT_LOC ( tokenizer . tokenize ( istr , file_in . c_str ( ) ) , file , line ) ;
2012-05-20 21:26:48 +02:00
// Check..
2023-09-11 20:26:22 +02:00
if ( onlyFormatStr ) {
CheckIO checkIO ( & tokenizer , & settings1 , this ) ;
checkIO . checkWrongPrintfScanfArguments ( ) ;
return ;
2021-02-20 13:00:30 +01:00
}
2023-09-11 20:26:22 +02:00
runChecks < CheckIO > ( tokenizer , this ) ;
2012-05-20 21:26:48 +02:00
}
2014-11-20 14:20:09 +01:00
void coutCerrMisusage ( ) {
2012-05-20 21:26:48 +02:00
check (
" void foo() { \n "
" std::cout << std::cout; \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (error) Invalid usage of output stream: '<< std::cout'. \n " , errout . str ( ) ) ;
2014-05-22 20:25:54 +02:00
check (
" void foo() { \n "
" std::cout << (std::cout); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (error) Invalid usage of output stream: '<< std::cout'. \n " , errout . str ( ) ) ;
2012-05-20 21:26:48 +02:00
check (
" void foo() { \n "
" std::cout << \" xyz \" << std::cout; \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (error) Invalid usage of output stream: '<< std::cout'. \n " , errout . str ( ) ) ;
check (
" void foo(int i) { \n "
" std::cout << i << std::cerr; \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (error) Invalid usage of output stream: '<< std::cerr'. \n " , errout . str ( ) ) ;
check (
" void foo() { \n "
" std::cout << \" xyz \" ; \n "
" std::cout << \" xyz \" ; \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check (
" void foo() { \n "
" std::cout << std::cout.good(); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2014-05-22 20:25:54 +02:00
check (
" void foo() { \n "
" unknownObject << std::cout; \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2012-05-20 21:26:48 +02:00
check (
" void foo() { \n "
" MACRO(std::cout <<, << std::cout) \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
}
2014-11-20 14:20:09 +01:00
void wrongMode_simple ( ) {
2012-05-22 14:30:22 +02:00
// Read mode
check ( " void foo(FILE*& f) { \n "
" f = fopen(name, \" r \" ); \n "
" fread(buffer, 5, 6, f); \n "
" rewind(f); \n "
" fwrite(buffer, 5, 6, f); \n "
" } " ) ;
2012-07-13 19:36:58 +02:00
ASSERT_EQUALS ( " [test.cpp:5]: (error) Write operation on a file that was opened only for reading. \n " , errout . str ( ) ) ;
2012-05-20 21:26:48 +02:00
2014-03-12 19:22:44 +01:00
check ( " void foo(FILE*& f) { \n "
" f = _wfopen(name, L \" r \" ); \n "
" fread(buffer, 5, 6, f); \n "
" rewind(f); \n "
" fwrite(buffer, 5, 6, f); \n "
2023-03-03 18:36:27 +01:00
" } " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2014-03-12 19:22:44 +01:00
ASSERT_EQUALS ( " [test.cpp:5]: (error) Write operation on a file that was opened only for reading. \n " , errout . str ( ) ) ;
check ( " void foo(FILE*& f) { \n "
" f = _tfopen(name, _T( \" r \" )); \n "
" fread(buffer, 5, 6, f); \n "
" rewind(f); \n "
" fwrite(buffer, 5, 6, f); \n "
2023-03-03 18:36:27 +01:00
" } " , false , false , cppcheck : : Platform : : Type : : Win32A ) ;
2014-03-12 19:22:44 +01:00
ASSERT_EQUALS ( " [test.cpp:5]: (error) Write operation on a file that was opened only for reading. \n " , errout . str ( ) ) ;
check ( " void foo(FILE*& f) { \n "
" f = _tfopen(name, _T( \" r \" )); \n "
" fread(buffer, 5, 6, f); \n "
" rewind(f); \n "
" fwrite(buffer, 5, 6, f); \n "
2023-03-03 18:36:27 +01:00
" } " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2014-03-12 19:22:44 +01:00
ASSERT_EQUALS ( " [test.cpp:5]: (error) Write operation on a file that was opened only for reading. \n " , errout . str ( ) ) ;
check ( " void foo(FILE*& f) { \n "
" _wfopen_s(&f, name, L \" r \" ); \n "
" fread(buffer, 5, 6, f); \n "
" rewind(f); \n "
" fwrite(buffer, 5, 6, f); \n "
2023-03-03 18:36:27 +01:00
" } " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2014-03-12 19:22:44 +01:00
ASSERT_EQUALS ( " [test.cpp:5]: (error) Write operation on a file that was opened only for reading. \n " , errout . str ( ) ) ;
check ( " void foo(FILE*& f) { \n "
" _tfopen_s(&f, name, _T( \" r \" )); \n "
" fread(buffer, 5, 6, f); \n "
" rewind(f); \n "
" fwrite(buffer, 5, 6, f); \n "
2023-03-03 18:36:27 +01:00
" } " , false , false , cppcheck : : Platform : : Type : : Win32A ) ;
2014-03-12 19:22:44 +01:00
ASSERT_EQUALS ( " [test.cpp:5]: (error) Write operation on a file that was opened only for reading. \n " , errout . str ( ) ) ;
check ( " void foo(FILE*& f) { \n "
" _tfopen_s(&f, name, _T( \" r \" )); \n "
" fread(buffer, 5, 6, f); \n "
" rewind(f); \n "
" fwrite(buffer, 5, 6, f); \n "
2023-03-03 18:36:27 +01:00
" } " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2014-03-12 19:22:44 +01:00
ASSERT_EQUALS ( " [test.cpp:5]: (error) Write operation on a file that was opened only for reading. \n " , errout . str ( ) ) ;
2012-05-22 14:30:22 +02:00
check ( " void foo(FILE*& f) { \n "
" f = fopen(name, \" r+ \" ); \n "
" fwrite(buffer, 5, 6, f); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2014-03-12 19:22:44 +01:00
check ( " void foo(FILE*& f) { \n "
" f = _wfopen(name, L \" r+ \" ); \n "
" fwrite(buffer, 5, 6, f); \n "
2023-03-03 18:36:27 +01:00
" } " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2014-03-12 19:22:44 +01:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo(FILE*& f) { \n "
" f = _tfopen(name, _T( \" r+ \" )); \n "
" fwrite(buffer, 5, 6, f); \n "
2023-03-03 18:36:27 +01:00
" } " , false , false , cppcheck : : Platform : : Type : : Win32A ) ;
2014-03-12 19:22:44 +01:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo(FILE*& f) { \n "
" f = _tfopen(name, _T( \" r+ \" )); \n "
" fwrite(buffer, 5, 6, f); \n "
2023-03-03 18:36:27 +01:00
" } " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2014-03-12 19:22:44 +01:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo(FILE*& f) { \n "
" _wfopen_s(&f, name, L \" r+ \" ); \n "
" fwrite(buffer, 5, 6, f); \n "
2023-03-03 18:36:27 +01:00
" } " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2014-03-12 19:22:44 +01:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo(FILE*& f) { \n "
" _tfopen_s(&f, name, _T( \" r+ \" )); \n "
" fwrite(buffer, 5, 6, f); \n "
2023-03-03 18:36:27 +01:00
" } " , false , false , cppcheck : : Platform : : Type : : Win32A ) ;
2014-03-12 19:22:44 +01:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo(FILE*& f) { \n "
" _tfopen_s(&f, name, _T( \" r+ \" )); \n "
" fwrite(buffer, 5, 6, f); \n "
2023-03-03 18:36:27 +01:00
" } " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2014-03-12 19:22:44 +01:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2017-10-03 17:25:15 +02:00
check ( " void foo(FILE*& f) { \n "
" f = tmpfile(); \n "
" fwrite(buffer, 5, 6, f); \n "
2023-03-03 18:36:27 +01:00
" } " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2017-10-03 17:25:15 +02:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2012-05-22 14:30:22 +02:00
// Write mode
check ( " void foo(FILE*& f) { \n "
" f = fopen(name, \" w \" ); \n "
" fwrite(buffer, 5, 6, f); \n "
" rewind(f); \n "
" fread(buffer, 5, 6, f); \n "
" } " ) ;
2012-07-13 19:36:58 +02:00
ASSERT_EQUALS ( " [test.cpp:5]: (error) Read operation on a file that was opened only for writing. \n " , errout . str ( ) ) ;
2012-05-22 14:30:22 +02:00
check ( " void foo(FILE*& f) { \n "
" f = fopen(name, \" w+ \" ); \n "
" fread(buffer, 5, 6, f); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2017-10-03 17:25:15 +02:00
check ( " void foo(FILE*& f) { \n "
" f = tmpfile(); \n "
" fread(buffer, 5, 6, f); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2012-05-22 14:30:22 +02:00
// Append mode
check ( " void foo(FILE*& f) { \n "
" f = fopen(name, \" a \" ); \n "
" fwrite(buffer, 5, 6, f); \n "
" rewind(f); \n "
" fread(buffer, 5, 6, f); \n "
" } " ) ;
2014-03-17 11:02:03 +01:00
ASSERT_EQUALS ( " [test.cpp:4]: (warning) Repositioning operation performed on a file opened in append mode has no effect. \n "
" [test.cpp:5]: (error) Read operation on a file that was opened only for writing. \n " , errout . str ( ) ) ;
2012-05-22 14:30:22 +02:00
check ( " void foo(FILE*& f) { \n "
" f = fopen(name, \" a+ \" ); \n "
" fread(buffer, 5, 6, f); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
// Variable declared locally
check ( " void foo() { \n "
" FILE* f = fopen(name, \" r \" ); \n "
" fwrite(buffer, 5, 6, f); \n "
" fclose(f); \n "
" } " ) ;
2012-07-13 19:36:58 +02:00
ASSERT_EQUALS ( " [test.cpp:3]: (error) Write operation on a file that was opened only for reading. \n " , errout . str ( ) ) ;
2012-05-22 14:30:22 +02:00
// Call unknown function
check ( " void foo(FILE*& f) { \n "
" f = fopen(name, \" a \" ); \n "
" fwrite(buffer, 5, 6, f); \n "
" bar(f); \n "
" fread(buffer, 5, 6, f); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2014-03-12 19:22:44 +01:00
// freopen and tmpfile
2012-05-22 14:30:22 +02:00
check ( " void foo(FILE*& f) { \n "
2014-03-12 19:22:44 +01:00
" f = freopen(name, \" r \" , f); \n "
2012-05-22 14:30:22 +02:00
" fwrite(buffer, 5, 6, f); \n "
" } " ) ;
2014-03-12 19:22:44 +01:00
ASSERT_EQUALS ( " [test.cpp:3]: (error) Write operation on a file that was opened only for reading. \n " , errout . str ( ) ) ;
2012-05-22 14:30:22 +02:00
check ( " void foo(FILE*& f) { \n "
2014-03-12 19:22:44 +01:00
" f = _wfreopen(name, L \" r \" , f); \n "
2012-05-22 14:30:22 +02:00
" fwrite(buffer, 5, 6, f); \n "
2023-03-03 18:36:27 +01:00
" } " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2014-03-12 19:22:44 +01:00
ASSERT_EQUALS ( " [test.cpp:3]: (error) Write operation on a file that was opened only for reading. \n " , errout . str ( ) ) ;
check ( " void foo(FILE*& f) { \n "
" f = _tfreopen(name, _T( \" r \" ), f); \n "
" fwrite(buffer, 5, 6, f); \n "
2023-03-03 18:36:27 +01:00
" } " , false , false , cppcheck : : Platform : : Type : : Win32A ) ;
2014-03-12 19:22:44 +01:00
ASSERT_EQUALS ( " [test.cpp:3]: (error) Write operation on a file that was opened only for reading. \n " , errout . str ( ) ) ;
check ( " void foo(FILE*& f) { \n "
" f = _tfreopen(name, _T( \" r \" ), f); \n "
" fwrite(buffer, 5, 6, f); \n "
2023-03-03 18:36:27 +01:00
" } " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2014-03-12 19:22:44 +01:00
ASSERT_EQUALS ( " [test.cpp:3]: (error) Write operation on a file that was opened only for reading. \n " , errout . str ( ) ) ;
check ( " void foo(FILE*& f) { \n "
" f = _wfreopen_s(&f, name, L \" r \" , f); \n "
" fwrite(buffer, 5, 6, f); \n "
2023-03-03 18:36:27 +01:00
" } " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2014-03-12 19:22:44 +01:00
ASSERT_EQUALS ( " [test.cpp:3]: (error) Write operation on a file that was opened only for reading. \n " , errout . str ( ) ) ;
check ( " void foo(FILE*& f) { \n "
" f = _tfreopen_s(&f, name, _T( \" r \" ), f); \n "
" fwrite(buffer, 5, 6, f); \n "
2023-03-03 18:36:27 +01:00
" } " , false , false , cppcheck : : Platform : : Type : : Win32A ) ;
2014-03-12 19:22:44 +01:00
ASSERT_EQUALS ( " [test.cpp:3]: (error) Write operation on a file that was opened only for reading. \n " , errout . str ( ) ) ;
check ( " void foo(FILE*& f) { \n "
" f = _tfreopen_s(&f, name, _T( \" r \" ), f); \n "
" fwrite(buffer, 5, 6, f); \n "
2023-03-03 18:36:27 +01:00
" } " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2012-07-13 19:36:58 +02:00
ASSERT_EQUALS ( " [test.cpp:3]: (error) Write operation on a file that was opened only for reading. \n " , errout . str ( ) ) ;
2012-05-22 14:30:22 +02:00
2012-05-23 10:04:21 +02:00
// Crash tests
2012-05-22 14:30:22 +02:00
check ( " void foo(FILE*& f) { \n "
2012-05-23 10:04:21 +02:00
" f = fopen(name, mode); \n " // No assertion failure (#3830)
2012-05-22 14:30:22 +02:00
" fwrite(buffer, 5, 6, f); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2012-05-23 10:04:21 +02:00
check ( " void fopen(std::string const &filepath, std::string const &mode); " ) ; // #3832
2012-05-22 14:30:22 +02:00
}
2014-11-20 14:20:09 +01:00
void wrongMode_complex ( ) {
2012-05-22 14:30:22 +02:00
check ( " void foo(FILE* f) { \n "
" if(a) f = fopen(name, \" w \" ); \n "
" else f = fopen(name, \" r \" ); \n "
" if(a) fwrite(buffer, 5, 6, f); \n "
" else fread(buffer, 5, 6, f); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo() { \n "
" FILE* f; \n "
" if(a) f = fopen(name, \" w \" ); \n "
" else f = fopen(name, \" r \" ); \n "
" if(a) fwrite(buffer, 5, 6, f); \n "
" else fread(buffer, 5, 6, f); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo() { \n "
" FILE* f = fopen(name, \" w \" ); \n "
" if(a) fwrite(buffer, 5, 6, f); \n "
" else fread(buffer, 5, 6, f); \n "
" } " ) ;
2012-07-13 19:36:58 +02:00
ASSERT_EQUALS ( " [test.cpp:4]: (error) Read operation on a file that was opened only for writing. \n " , errout . str ( ) ) ;
2012-05-22 14:30:22 +02:00
}
2014-11-20 14:20:09 +01:00
void useClosedFile ( ) {
2012-05-22 14:30:22 +02:00
check ( " void foo(FILE*& f) { \n "
" fclose(f); \n "
" fwrite(buffer, 5, 6, f); \n "
" clearerr(f); \n "
" fread(buffer, 5, 6, f); \n "
" ungetc('a', f); \n "
2014-03-12 19:22:44 +01:00
" ungetwc(L'a', f); \n "
2017-09-29 16:12:50 +02:00
" rewind(f); \n "
2012-05-22 14:30:22 +02:00
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:3]: (error) Used file that is not opened. \n "
" [test.cpp:4]: (error) Used file that is not opened. \n "
" [test.cpp:5]: (error) Used file that is not opened. \n "
2014-03-12 19:22:44 +01:00
" [test.cpp:6]: (error) Used file that is not opened. \n "
2017-09-29 16:12:50 +02:00
" [test.cpp:7]: (error) Used file that is not opened. \n "
" [test.cpp:8]: (error) Used file that is not opened. \n " , errout . str ( ) ) ;
2012-05-22 14:30:22 +02:00
check ( " void foo(FILE*& f) { \n "
" if(!ferror(f)) { \n "
" fclose(f); \n "
" return; "
" } \n "
" fwrite(buffer, 5, 6, f); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo(FILE*& f) { \n "
" fclose(f); \n "
" f = fopen(name, \" r \" ); \n "
" fread(buffer, 5, 6, f); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo(FILE*& f) { \n "
" f = fopen(name, \" r \" ); \n "
" f = g; \n "
" fwrite(buffer, 5, 6, f); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2012-06-24 18:57:17 +02:00
check ( " void foo() { \n "
" FILE* f; \n "
" fwrite(buffer, 5, 6, f); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:3]: (error) Used file that is not opened. \n " , errout . str ( ) ) ;
check ( " void foo() { \n "
" FILE* f(stdout); \n "
" fwrite(buffer, 5, 6, f); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2012-07-29 13:04:12 +02:00
check ( " void foo() { \n " // #3965
" FILE* f[3]; \n "
" f[0] = fopen(name, mode); \n "
" fclose(f[0]); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2012-12-08 09:26:10 +01:00
// #4368: multiple functions
check ( " static FILE *fp = NULL; \n "
" \n "
" void close() \n "
" { \n "
" fclose(fp); \n "
" } \n "
" \n "
" void dump() \n "
" { \n "
" if (fp == NULL) return; \n "
" fprintf(fp, \" Here's the output. \\ n \" ); \n "
" } \n "
" \n "
" int main() \n "
" { \n "
" fp = fopen( \" test.txt \" , \" w \" ); \n "
" dump(); \n "
" close(); \n "
" return 0; \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " static FILE *fp = NULL; \n "
" \n "
" void close() \n "
" { \n "
" fclose(fp); \n "
" } \n "
" \n "
" void dump() \n "
" { \n "
" fclose(fp); \n "
" fprintf(fp, \" Here's the output. \\ n \" ); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:11]: (error) Used file that is not opened. \n " , errout . str ( ) ) ;
2013-02-15 17:30:43 +01:00
// #4466
check ( " void chdcd_parse_nero(FILE *infile) { \n "
" switch (mode) { \n "
" case 0x0300: \n "
" fclose(infile); \n "
" return; \n "
" case 0x0500: \n "
" fclose(infile); \n "
" return; \n "
" } \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2013-03-15 06:42:46 +01:00
2016-01-31 10:39:35 +01:00
check ( " void chdcd_parse_nero(FILE *infile) { \n "
" switch (mode) { \n "
" case 0x0300: \n "
" fclose(infile); \n "
" exit(0); \n "
" case 0x0500: \n "
" fclose(infile); \n "
" return; \n "
" } \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2013-03-15 06:42:46 +01:00
// #4649
check ( " void foo() { \n "
" struct {FILE *f1; FILE *f2;} a; \n "
" a.f1 = fopen(name,mode); \n "
" a.f2 = fopen(name,mode); \n "
" fclose(a.f1); \n "
" fclose(a.f2); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2014-03-28 11:34:23 +01:00
// #1473
check ( " void foo() { \n "
" FILE *a = fopen( \" aa \" , \" r \" ); \n "
" while (fclose(a)) {} \n "
" } " ) ;
2020-05-20 18:52:46 +02:00
TODO_ASSERT_EQUALS ( " [test.cpp:3]: (error) Used file that is not opened. \n " , " " , errout . str ( ) ) ;
2015-07-20 22:40:19 +02:00
// #6823
check ( " void foo() { \n "
" FILE f[2]; \n "
" f[0] = fopen( \" 1 \" , \" w \" ); \n "
" f[1] = fopen( \" 2 \" , \" w \" ); \n "
" fclose(f[0]); \n "
" fclose(f[1]); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2012-05-22 14:30:22 +02:00
}
2014-11-20 14:20:09 +01:00
void fileIOwithoutPositioning ( ) {
2012-05-22 14:30:22 +02:00
check ( " void foo(FILE* f) { \n "
" fwrite(buffer, 5, 6, f); \n "
" fread(buffer, 5, 6, f); \n "
" } " ) ;
2012-07-21 15:54:04 +02:00
ASSERT_EQUALS ( " [test.cpp:3]: (error) Read and write operations without a call to a positioning function (fseek, fsetpos or rewind) or fflush in between result in undefined behaviour. \n " , errout . str ( ) ) ;
2012-05-22 14:30:22 +02:00
check ( " void foo(FILE* f) { \n "
" fread(buffer, 5, 6, f); \n "
" fwrite(buffer, 5, 6, f); \n "
" } " ) ;
2012-07-21 15:54:04 +02:00
ASSERT_EQUALS ( " [test.cpp:3]: (error) Read and write operations without a call to a positioning function (fseek, fsetpos or rewind) or fflush in between result in undefined behaviour. \n " , errout . str ( ) ) ;
2012-05-22 14:30:22 +02:00
check ( " void foo(FILE* f, bool read) { \n "
" if(read) \n "
" fread(buffer, 5, 6, f); \n "
" else \n "
" fwrite(buffer, 5, 6, f); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo(FILE* f) { \n "
" fread(buffer, 5, 6, f); \n "
" fflush(f); \n "
" fwrite(buffer, 5, 6, f); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo(FILE* f) { \n "
" fread(buffer, 5, 6, f); \n "
" rewind(f); \n "
" fwrite(buffer, 5, 6, f); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo(FILE* f) { \n "
" fread(buffer, 5, 6, f); \n "
" fsetpos(f, pos); \n "
" fwrite(buffer, 5, 6, f); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo(FILE* f) { \n "
" fread(buffer, 5, 6, f); \n "
" fseek(f, 0, SEEK_SET); \n "
" fwrite(buffer, 5, 6, f); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo(FILE* f) { \n "
" fread(buffer, 5, 6, f); \n "
" long pos = ftell(f); \n "
" fwrite(buffer, 5, 6, f); \n "
" } " ) ;
2012-07-21 15:54:04 +02:00
ASSERT_EQUALS ( " [test.cpp:4]: (error) Read and write operations without a call to a positioning function (fseek, fsetpos or rewind) or fflush in between result in undefined behaviour. \n " , errout . str ( ) ) ;
2015-01-27 21:52:52 +01:00
// #6452 - member functions
check ( " class FileStream { \n "
" void insert(const ByteVector &data, ulong start); \n "
" void seek(long offset, Position p); \n "
" FileStreamPrivate *d; \n "
" }; \n "
" void FileStream::insert(const ByteVector &data, ulong start) { \n "
" int bytesRead = fread(aboutToOverwrite.data(), 1, bufferLength, d->file); \n "
" seek(writePosition); \n "
" fwrite(buffer.data(), sizeof(char), buffer.size(), d->file); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " class FileStream { \n "
" void insert(const ByteVector &data, ulong start); \n "
" FileStreamPrivate *d; \n "
" }; \n "
" void FileStream::insert(const ByteVector &data, ulong start) { \n "
" int bytesRead = fread(aboutToOverwrite.data(), 1, bufferLength, d->file); \n "
" unknown(writePosition); \n "
" fwrite(buffer.data(), sizeof(char), buffer.size(), d->file); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " class FileStream { \n "
" void insert(const ByteVector &data, ulong start); \n "
" FileStreamPrivate *d; \n "
" }; \n "
" void known(int); \n "
" void FileStream::insert(const ByteVector &data, ulong start) { \n "
" int bytesRead = fread(aboutToOverwrite.data(), 1, bufferLength, d->file); \n "
" known(writePosition); \n "
" fwrite(buffer.data(), sizeof(char), buffer.size(), d->file); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:9]: (error) Read and write operations without a call to a positioning function (fseek, fsetpos or rewind) or fflush in between result in undefined behaviour. \n " , errout . str ( ) ) ;
check ( " class FileStream { \n "
" void insert(const ByteVector &data, ulong start); \n "
" FileStreamPrivate *d; \n "
" }; \n "
" void known(int); \n "
" void FileStream::insert(const ByteVector &data, ulong start) { \n "
" int bytesRead = fread(X::data(), 1, bufferLength, d->file); \n "
" known(writePosition); \n "
" fwrite(X::data(), sizeof(char), buffer.size(), d->file); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:9]: (error) Read and write operations without a call to a positioning function (fseek, fsetpos or rewind) or fflush in between result in undefined behaviour. \n " , errout . str ( ) ) ;
2012-05-22 14:30:22 +02:00
}
2014-11-20 14:20:09 +01:00
void seekOnAppendedFile ( ) {
2014-03-17 11:02:03 +01:00
check ( " void foo() { \n "
" FILE* f = fopen( \" \" , \" a+ \" ); \n "
" fseek(f, 0, SEEK_SET); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo() { \n "
" FILE* f = fopen( \" \" , \" w \" ); \n "
" fseek(f, 0, SEEK_SET); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo() { \n "
" FILE* f = fopen( \" \" , \" a \" ); \n "
" fseek(f, 0, SEEK_SET); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:3]: (warning) Repositioning operation performed on a file opened in append mode has no effect. \n " , errout . str ( ) ) ;
2014-03-18 13:44:27 +01:00
check ( " void foo() { \n "
" FILE* f = fopen( \" \" , \" a \" ); \n "
" fflush(f); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ; // #5578
2015-10-13 15:31:58 +02:00
check ( " void foo() { \n "
" FILE* f = fopen( \" \" , \" a \" ); \n "
" fclose(f); \n "
" f = fopen( \" \" , \" r \" ); \n "
" fseek(f, 0, SEEK_SET); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ; // #6566
2014-03-17 11:02:03 +01:00
}
2014-11-20 14:20:09 +01:00
void fflushOnInputStream ( ) {
2012-05-20 21:26:48 +02:00
check ( " void foo() \n "
" { \n "
" fflush(stdin); \n "
2014-08-31 20:56:05 +02:00
" } " , false , true ) ;
ASSERT_EQUALS ( " [test.cpp:3]: (portability) fflush() called on input stream 'stdin' may result in undefined behaviour on non-linux systems. \n " , errout . str ( ) ) ;
2012-05-20 21:26:48 +02:00
check ( " void foo() \n "
" { \n "
" fflush(stdout); \n "
2014-08-31 20:56:05 +02:00
" } " , false , true ) ;
2012-05-20 21:26:48 +02:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2014-08-31 21:03:33 +02:00
check ( " void foo(FILE*& f) { \n "
" f = fopen(path, \" r \" ); \n "
" fflush(f); \n "
" } " , false , true ) ;
ASSERT_EQUALS ( " [test.cpp:3]: (portability) fflush() called on input stream 'f' may result in undefined behaviour on non-linux systems. \n " , errout . str ( ) ) ;
check ( " void foo(FILE*& f) { \n "
" f = fopen(path, \" w \" ); \n "
" fflush(f); \n "
" } " , false , true ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo(FILE*& f) { \n "
" fflush(f); \n "
" } " , false , true ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2012-05-20 21:26:48 +02:00
}
2021-07-10 13:59:47 +02:00
void incompatibleFileOpen ( ) {
check ( " void foo() { \n "
" FILE *f1 = fopen( \" tmp \" , \" wt \" ); \n "
" FILE *f2 = fopen( \" tmp \" , \" rt \" ); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:3]: (warning) The file ' \" tmp \" ' is opened for read and write access at the same time on different streams \n " , errout . str ( ) ) ;
}
2012-05-20 21:26:48 +02:00
2014-11-20 14:20:09 +01:00
void testScanf1 ( ) {
2012-07-07 13:34:37 +02:00
check ( " void foo() { \n "
2012-05-20 21:26:48 +02:00
" int a, b; \n "
" FILE *file = fopen( \" test \" , \" r \" ); \n "
2012-07-07 13:34:37 +02:00
" a = fscanf(file, \" aa %s \" , bar); \n "
" b = scanf( \" aa %S \" , bar); \n "
" b = scanf( \" aa %ls \" , bar); \n "
" sscanf(foo, \" %[^~] \" , bar); \n "
" scanf( \" %dx%s \" , &b, bar); \n "
2012-05-20 21:26:48 +02:00
" fclose(file); \n "
" } " ) ;
2016-05-26 21:10:50 +02:00
ASSERT_EQUALS ( " [test.cpp:4]: (warning) fscanf() without field width limits can crash with huge input data. \n "
" [test.cpp:5]: (warning) scanf() without field width limits can crash with huge input data. \n "
" [test.cpp:6]: (warning) scanf() without field width limits can crash with huge input data. \n "
" [test.cpp:7]: (warning) sscanf() without field width limits can crash with huge input data. \n "
" [test.cpp:8]: (warning) scanf() without field width limits can crash with huge input data. \n " , errout . str ( ) ) ;
2012-05-20 21:26:48 +02:00
}
2014-11-20 14:20:09 +01:00
void testScanf2 ( ) {
2012-07-07 13:34:37 +02:00
check ( " void foo() { \n "
" scanf( \" %5s \" , bar); \n " // Width specifier given
" scanf( \" %5[^~] \" , bar); \n " // Width specifier given
" scanf( \" aa%%s \" , bar); \n " // No %s
" scanf( \" aa%d \" , &a); \n " // No %s
" scanf( \" aa%ld \" , &a); \n " // No %s
" scanf( \" %*[^~] \" ); \n " // Ignore input
" } " ) ;
2013-09-30 19:55:21 +02:00
ASSERT_EQUALS ( " [test.cpp:4]: (warning) scanf format string requires 0 parameters but 1 is given. \n " , errout . str ( ) ) ;
2012-05-20 21:26:48 +02:00
}
2016-05-22 14:00:26 +02:00
void testScanf3 ( ) { // ticket #3494
check ( " void f() { \n "
" char str[8]; \n "
" scanf( \" %7c \" , str); \n "
" scanf( \" %8c \" , str); \n "
" scanf( \" %9c \" , str); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:5]: (error) Width 9 given in format string (no. 1) is larger than destination buffer 'str[8]', use %8c to prevent overflowing it. \n " , errout . str ( ) ) ;
}
2014-11-20 14:20:09 +01:00
void testScanf4 ( ) { // ticket #2553
2012-07-24 15:54:38 +02:00
check ( " void f() \n "
" { \n "
" char str [8]; \n "
" scanf ( \" %70s \" ,str); \n "
2013-03-20 15:36:16 +01:00
" } " ) ;
2012-07-24 15:54:38 +02:00
ASSERT_EQUALS ( " [test.cpp:4]: (error) Width 70 given in format string (no. 1) is larger than destination buffer 'str[8]', use %7s to prevent overflowing it. \n " , errout . str ( ) ) ;
}
2021-12-01 09:51:48 +01:00
void testScanf5 ( ) { // #10632
check ( " char s1[42], s2[42]; \n "
" void test() { \n "
" scanf( \" %42s%42[a-z] \" , s1, s2); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:3]: (error) Width 42 given in format string (no. 1) is larger than destination buffer 's1[42]', use %41s to prevent overflowing it. \n "
" [test.cpp:3]: (error) Width 42 given in format string (no. 2) is larger than destination buffer 's2[42]', use %41[a-z] to prevent overflowing it. \n " , errout . str ( ) ) ;
}
2016-01-12 20:03:42 +01:00
2021-08-07 20:51:18 +02:00
# define TEST_SCANF_CODE(format, type) \
2017-03-08 15:16:19 +01:00
" void f(){ " type " x; scanf( \" " format " \" , &x);} "
2016-10-24 21:43:58 +02:00
2021-08-07 20:51:18 +02:00
# define TEST_SCANF_ERR(format, formatStr, type) \
2023-02-23 22:53:39 +01:00
" [test.c:1]: (warning) " format " in format string (no. 1) requires ' " formatStr " *' but the argument type is ' " type " *'. \n "
# define TEST_SCANF_ERR_AKA_(file, format, formatStr, type, akaType) \
" [ " file " :1]: (portability) " format " in format string (no. 1) requires ' " formatStr " *' but the argument type is ' " type " * {aka " akaType " *}'. \n "
2016-10-24 21:43:58 +02:00
2021-08-07 20:51:18 +02:00
# define TEST_SCANF_ERR_AKA(format, formatStr, type, akaType) \
2023-02-23 22:53:39 +01:00
TEST_SCANF_ERR_AKA_ ( " test.c " , format , formatStr , type , akaType )
# define TEST_SCANF_ERR_AKA_CPP(format, formatStr, type, akaType) \
TEST_SCANF_ERR_AKA_ ( " test.cpp " , format , formatStr , type , akaType )
2016-10-24 21:43:58 +02:00
2021-08-07 20:51:18 +02:00
# define TEST_PRINTF_CODE(format, type) \
2017-11-10 21:53:53 +01:00
" void f( " type " x){printf( \" " format " \" , x);} "
2021-08-07 20:51:18 +02:00
# define TEST_PRINTF_ERR(format, requiredType, actualType) \
2023-02-23 22:53:39 +01:00
" [test.c:1]: (warning) " format " in format string (no. 1) requires ' " requiredType " ' but the argument type is ' " actualType " '. \n "
# define TEST_PRINTF_ERR_AKA_(file, format, requiredType, actualType, akaType) \
" [ " file " :1]: (portability) " format " in format string (no. 1) requires ' " requiredType " ' but the argument type is ' " actualType " {aka " akaType " }'. \n "
2017-11-10 21:53:53 +01:00
2021-08-07 20:51:18 +02:00
# define TEST_PRINTF_ERR_AKA(format, requiredType, actualType, akaType) \
2023-02-23 22:53:39 +01:00
TEST_PRINTF_ERR_AKA_ ( " test.c " , format , requiredType , actualType , akaType )
# define TEST_PRINTF_ERR_AKA_CPP(format, requiredType, actualType, akaType) \
TEST_PRINTF_ERR_AKA_ ( " test.cpp " , format , requiredType , actualType , akaType )
2016-10-24 21:43:58 +02:00
2023-02-23 22:53:39 +01:00
void testFormatStrNoWarn ( const char * filename , unsigned int linenr , const char * code ,
bool cpp = false ) {
2023-03-03 18:36:27 +01:00
check ( code , true , false , cppcheck : : Platform : : Type : : Unix32 , true , cpp ) ;
2021-02-20 13:00:30 +01:00
assertEquals ( filename , linenr , emptyString , errout . str ( ) ) ;
2023-03-03 18:36:27 +01:00
check ( code , true , false , cppcheck : : Platform : : Type : : Unix64 , true , cpp ) ;
2021-02-20 13:00:30 +01:00
assertEquals ( filename , linenr , emptyString , errout . str ( ) ) ;
2023-03-03 18:36:27 +01:00
check ( code , true , false , cppcheck : : Platform : : Type : : Win32A , true , cpp ) ;
2021-02-20 13:00:30 +01:00
assertEquals ( filename , linenr , emptyString , errout . str ( ) ) ;
2023-03-03 18:36:27 +01:00
check ( code , true , false , cppcheck : : Platform : : Type : : Win64 , true , cpp ) ;
2021-02-20 13:00:30 +01:00
assertEquals ( filename , linenr , emptyString , errout . str ( ) ) ;
2016-10-24 21:43:58 +02:00
}
2021-02-20 13:00:30 +01:00
void testFormatStrWarn ( const char * filename , unsigned int linenr ,
2023-02-23 22:53:39 +01:00
const char * code , const char * testScanfErrString ,
bool cpp = false ) {
2023-03-03 18:36:27 +01:00
check ( code , true , false , cppcheck : : Platform : : Type : : Unix32 , true , cpp ) ;
2016-10-24 21:43:58 +02:00
assertEquals ( filename , linenr , testScanfErrString , errout . str ( ) ) ;
2023-03-03 18:36:27 +01:00
check ( code , true , false , cppcheck : : Platform : : Type : : Unix64 , true , cpp ) ;
2016-10-24 21:43:58 +02:00
assertEquals ( filename , linenr , testScanfErrString , errout . str ( ) ) ;
2023-03-03 18:36:27 +01:00
check ( code , true , false , cppcheck : : Platform : : Type : : Win32A , true , cpp ) ;
2016-10-24 21:43:58 +02:00
assertEquals ( filename , linenr , testScanfErrString , errout . str ( ) ) ;
2023-03-03 18:36:27 +01:00
check ( code , true , false , cppcheck : : Platform : : Type : : Win64 , true , cpp ) ;
2016-10-24 21:43:58 +02:00
assertEquals ( filename , linenr , testScanfErrString , errout . str ( ) ) ;
}
2021-02-20 13:00:30 +01:00
void testFormatStrWarnAka ( const char * filename , unsigned int linenr ,
2023-02-23 22:53:39 +01:00
const char * code , const char * testScanfErrAkaString , const char * testScanfErrAkaWin64String ,
bool cpp = false ) {
2023-03-03 18:36:27 +01:00
check ( code , true , true , cppcheck : : Platform : : Type : : Unix32 , true , cpp ) ;
2016-10-24 21:43:58 +02:00
assertEquals ( filename , linenr , testScanfErrAkaString , errout . str ( ) ) ;
2023-03-03 18:36:27 +01:00
check ( code , true , true , cppcheck : : Platform : : Type : : Unix64 , true , cpp ) ;
2016-10-24 21:43:58 +02:00
assertEquals ( filename , linenr , testScanfErrAkaString , errout . str ( ) ) ;
2023-03-03 18:36:27 +01:00
check ( code , true , true , cppcheck : : Platform : : Type : : Win32A , true , cpp ) ;
2016-10-24 21:43:58 +02:00
assertEquals ( filename , linenr , testScanfErrAkaString , errout . str ( ) ) ;
2023-03-03 18:36:27 +01:00
check ( code , true , true , cppcheck : : Platform : : Type : : Win64 , true , cpp ) ;
2016-10-24 21:43:58 +02:00
assertEquals ( filename , linenr , testScanfErrAkaWin64String , errout . str ( ) ) ;
}
2021-02-20 13:00:30 +01:00
void testFormatStrWarnAkaWin64 ( const char * filename , unsigned int linenr ,
2023-02-23 22:53:39 +01:00
const char * code , const char * testScanfErrAkaWin64String ,
bool cpp = false ) {
2023-03-03 18:36:27 +01:00
check ( code , true , true , cppcheck : : Platform : : Type : : Unix32 , true , cpp ) ;
2021-02-20 13:00:30 +01:00
assertEquals ( filename , linenr , emptyString , errout . str ( ) ) ;
2023-03-03 18:36:27 +01:00
check ( code , true , true , cppcheck : : Platform : : Type : : Unix64 , true , cpp ) ;
2021-02-20 13:00:30 +01:00
assertEquals ( filename , linenr , emptyString , errout . str ( ) ) ;
2023-03-03 18:36:27 +01:00
check ( code , true , true , cppcheck : : Platform : : Type : : Win32A , true , cpp ) ;
2021-02-20 13:00:30 +01:00
assertEquals ( filename , linenr , emptyString , errout . str ( ) ) ;
2023-03-03 18:36:27 +01:00
check ( code , true , true , cppcheck : : Platform : : Type : : Win64 , true , cpp ) ;
2016-10-24 21:43:58 +02:00
assertEquals ( filename , linenr , testScanfErrAkaWin64String , errout . str ( ) ) ;
}
2021-02-20 13:00:30 +01:00
void testFormatStrWarnAkaWin32 ( const char * filename , unsigned int linenr ,
2023-02-23 22:53:39 +01:00
const char * code , const char * testScanfErrAkaString ,
bool cpp = false ) {
2023-03-03 18:36:27 +01:00
check ( code , true , true , cppcheck : : Platform : : Type : : Unix32 , true , cpp ) ;
2016-10-24 21:43:58 +02:00
assertEquals ( filename , linenr , testScanfErrAkaString , errout . str ( ) ) ;
2023-03-03 18:36:27 +01:00
check ( code , true , true , cppcheck : : Platform : : Type : : Unix64 , true , cpp ) ;
2016-10-24 21:43:58 +02:00
assertEquals ( filename , linenr , testScanfErrAkaString , errout . str ( ) ) ;
2023-03-03 18:36:27 +01:00
check ( code , true , true , cppcheck : : Platform : : Type : : Win32A , true , cpp ) ;
2016-10-24 21:43:58 +02:00
assertEquals ( filename , linenr , testScanfErrAkaString , errout . str ( ) ) ;
2023-03-03 18:36:27 +01:00
check ( code , true , true , cppcheck : : Platform : : Type : : Win64 , true , cpp ) ;
2021-02-20 13:00:30 +01:00
assertEquals ( filename , linenr , emptyString , errout . str ( ) ) ;
2016-10-24 21:43:58 +02:00
}
2016-01-12 20:03:42 +01:00
2016-10-24 21:43:58 +02:00
# define TEST_SCANF_NOWARN(FORMAT, FORMATSTR, TYPE) \
2021-02-20 13:00:30 +01:00
testFormatStrNoWarn ( __FILE__ , __LINE__ , TEST_SCANF_CODE ( FORMAT , TYPE ) )
2023-02-23 22:53:39 +01:00
# define TEST_SCANF_NOWARN_CPP(FORMAT, FORMATSTR, TYPE) \
testFormatStrNoWarn ( __FILE__ , __LINE__ , TEST_SCANF_CODE ( FORMAT , TYPE ) , true )
2016-10-24 21:43:58 +02:00
# define TEST_SCANF_WARN(FORMAT, FORMATSTR, TYPE) \
2021-02-20 13:00:30 +01:00
testFormatStrWarn ( __FILE__ , __LINE__ , TEST_SCANF_CODE ( FORMAT , TYPE ) , TEST_SCANF_ERR ( FORMAT , FORMATSTR , TYPE ) )
2016-10-24 21:43:58 +02:00
# define TEST_SCANF_WARN_AKA(FORMAT, FORMATSTR, TYPE, AKATYPE, AKATYPE_WIN64) \
2021-02-20 13:00:30 +01:00
testFormatStrWarnAka ( __FILE__ , __LINE__ , TEST_SCANF_CODE ( FORMAT , TYPE ) , TEST_SCANF_ERR_AKA ( FORMAT , FORMATSTR , TYPE , AKATYPE ) , TEST_SCANF_ERR_AKA ( FORMAT , FORMATSTR , TYPE , AKATYPE_WIN64 ) )
2023-02-23 22:53:39 +01:00
# define TEST_SCANF_WARN_AKA_CPP(FORMAT, FORMATSTR, TYPE, AKATYPE, AKATYPE_WIN64) \
testFormatStrWarnAka ( __FILE__ , __LINE__ , TEST_SCANF_CODE ( FORMAT , TYPE ) , TEST_SCANF_ERR_AKA_CPP ( FORMAT , FORMATSTR , TYPE , AKATYPE ) , TEST_SCANF_ERR_AKA_CPP ( FORMAT , FORMATSTR , TYPE , AKATYPE_WIN64 ) , true )
2016-10-24 21:43:58 +02:00
# define TEST_SCANF_WARN_AKA_WIN64(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN64) \
2021-02-20 13:00:30 +01:00
testFormatStrWarnAkaWin64 ( __FILE__ , __LINE__ , TEST_SCANF_CODE ( FORMAT , TYPE ) , TEST_SCANF_ERR_AKA ( FORMAT , FORMATSTR , TYPE , AKATYPE_WIN64 ) )
2023-02-23 22:53:39 +01:00
# define TEST_SCANF_WARN_AKA_CPP_WIN64(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN64) \
testFormatStrWarnAkaWin64 ( __FILE__ , __LINE__ , TEST_SCANF_CODE ( FORMAT , TYPE ) , TEST_SCANF_ERR_AKA_CPP ( FORMAT , FORMATSTR , TYPE , AKATYPE_WIN64 ) , true )
2016-10-24 21:43:58 +02:00
# define TEST_SCANF_WARN_AKA_WIN32(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN32) \
2021-02-20 13:00:30 +01:00
testFormatStrWarnAkaWin32 ( __FILE__ , __LINE__ , TEST_SCANF_CODE ( FORMAT , TYPE ) , TEST_SCANF_ERR_AKA ( FORMAT , FORMATSTR , TYPE , AKATYPE_WIN32 ) )
2023-02-23 22:53:39 +01:00
# define TEST_SCANF_WARN_AKA_CPP_WIN32(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN32) \
testFormatStrWarnAkaWin32 ( __FILE__ , __LINE__ , TEST_SCANF_CODE ( FORMAT , TYPE ) , TEST_SCANF_ERR_AKA_CPP ( FORMAT , FORMATSTR , TYPE , AKATYPE_WIN32 ) , true )
2016-01-12 16:43:27 +01:00
2017-11-10 21:53:53 +01:00
# define TEST_PRINTF_NOWARN(FORMAT, FORMATSTR, TYPE) \
2021-02-20 13:00:30 +01:00
testFormatStrNoWarn ( __FILE__ , __LINE__ , TEST_PRINTF_CODE ( FORMAT , TYPE ) )
2023-02-23 22:53:39 +01:00
# define TEST_PRINTF_NOWARN_CPP(FORMAT, FORMATSTR, TYPE) \
testFormatStrNoWarn ( __FILE__ , __LINE__ , TEST_PRINTF_CODE ( FORMAT , TYPE ) , true )
2017-11-10 21:53:53 +01:00
# define TEST_PRINTF_WARN(FORMAT, FORMATSTR, TYPE) \
2021-02-20 13:00:30 +01:00
testFormatStrWarn ( __FILE__ , __LINE__ , TEST_PRINTF_CODE ( FORMAT , TYPE ) , TEST_PRINTF_ERR ( FORMAT , FORMATSTR , TYPE ) )
2017-11-10 21:53:53 +01:00
# define TEST_PRINTF_WARN_AKA(FORMAT, FORMATSTR, TYPE, AKATYPE, AKATYPE_WIN64) \
2021-02-20 13:00:30 +01:00
testFormatStrWarnAka ( __FILE__ , __LINE__ , TEST_PRINTF_CODE ( FORMAT , TYPE ) , TEST_PRINTF_ERR_AKA ( FORMAT , FORMATSTR , TYPE , AKATYPE ) , TEST_PRINTF_ERR_AKA ( FORMAT , FORMATSTR , TYPE , AKATYPE_WIN64 ) )
2023-02-23 22:53:39 +01:00
# define TEST_PRINTF_WARN_AKA_CPP(FORMAT, FORMATSTR, TYPE, AKATYPE, AKATYPE_WIN64) \
testFormatStrWarnAka ( __FILE__ , __LINE__ , TEST_PRINTF_CODE ( FORMAT , TYPE ) , TEST_PRINTF_ERR_AKA_CPP ( FORMAT , FORMATSTR , TYPE , AKATYPE ) , TEST_PRINTF_ERR_AKA_CPP ( FORMAT , FORMATSTR , TYPE , AKATYPE_WIN64 ) , true )
2017-11-10 21:53:53 +01:00
# define TEST_PRINTF_WARN_AKA_WIN64(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN64) \
2021-02-20 13:00:30 +01:00
testFormatStrWarnAkaWin64 ( __FILE__ , __LINE__ , TEST_PRINTF_CODE ( FORMAT , TYPE ) , TEST_PRINTF_ERR_AKA ( FORMAT , FORMATSTR , TYPE , AKATYPE_WIN64 ) )
2023-02-23 22:53:39 +01:00
# define TEST_PRINTF_WARN_AKA_CPP_WIN64(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN64) \
testFormatStrWarnAkaWin64 ( __FILE__ , __LINE__ , TEST_PRINTF_CODE ( FORMAT , TYPE ) , TEST_PRINTF_ERR_AKA_CPP ( FORMAT , FORMATSTR , TYPE , AKATYPE_WIN64 ) , true )
2017-11-10 21:53:53 +01:00
# define TEST_PRINTF_WARN_AKA_WIN32(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN32) \
2021-02-20 13:00:30 +01:00
testFormatStrWarnAkaWin32 ( __FILE__ , __LINE__ , TEST_PRINTF_CODE ( FORMAT , TYPE ) , TEST_PRINTF_ERR_AKA ( FORMAT , FORMATSTR , TYPE , AKATYPE_WIN32 ) )
2023-02-23 22:53:39 +01:00
# define TEST_PRINTF_WARN_AKA_CPP_WIN32(FORMAT, FORMATSTR, TYPE, AKATYPE_WIN32) \
testFormatStrWarnAkaWin32 ( __FILE__ , __LINE__ , TEST_PRINTF_CODE ( FORMAT , TYPE ) , TEST_PRINTF_ERR_AKA_CPP ( FORMAT , FORMATSTR , TYPE , AKATYPE_WIN32 ) , true )
2017-11-10 21:53:53 +01:00
2014-11-20 14:20:09 +01:00
void testScanfArgument ( ) {
2012-05-20 21:26:48 +02:00
check ( " void foo() { \n "
" scanf( \" %1d \" , &foo); \n "
" sscanf(bar, \" %1d \" , &foo); \n "
" scanf( \" %1u%1u \" , &foo, bar()); \n "
" scanf( \" %*1x %1x %29s \" , &count, KeyName); \n " // #3373
" fscanf(f, \" %7ms \" , &ref); \n " // #3461
2012-07-07 13:34:37 +02:00
" sscanf(ip_port, \" %*[^:]:%4d \" , &port); \n " // #3468
2012-05-20 21:26:48 +02:00
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo() { \n "
" scanf( \" \" , &foo); \n "
" scanf( \" %1d \" , &foo, &bar); \n "
" fscanf(bar, \" %1d \" , &foo, &bar); \n "
" scanf( \" %*1x %1x %29s \" , &count, KeyName, foo); \n "
" } " ) ;
2013-09-30 19:55:21 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) scanf format string requires 0 parameters but 1 is given. \n "
" [test.cpp:3]: (warning) scanf format string requires 1 parameter but 2 are given. \n "
" [test.cpp:4]: (warning) fscanf format string requires 1 parameter but 2 are given. \n "
" [test.cpp:5]: (warning) scanf format string requires 2 parameters but 3 are given. \n " , errout . str ( ) ) ;
2012-05-20 21:26:48 +02:00
check ( " void foo() { \n "
" scanf( \" %1d \" ); \n "
" scanf( \" %1u%1u \" , bar()); \n "
" sscanf(bar, \" %1d%1d \" , &foo); \n "
" scanf( \" %*1x %1x %29s \" , &count); \n "
" } " ) ;
2013-09-30 19:55:21 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (error) scanf format string requires 1 parameter but only 0 are given. \n "
" [test.cpp:3]: (error) scanf format string requires 2 parameters but only 1 is given. \n "
" [test.cpp:4]: (error) sscanf format string requires 2 parameters but only 1 is given. \n "
" [test.cpp:5]: (error) scanf format string requires 2 parameters but only 1 is given. \n " , errout . str ( ) ) ;
2012-06-23 07:52:52 +02:00
check ( " void foo() { \n "
" char input[10]; \n "
" char output[5]; \n "
" sscanf(input, \" %3s \" , output); \n "
" sscanf(input, \" %4s \" , output); \n "
" sscanf(input, \" %5s \" , output); \n "
" } " , false ) ;
2012-07-13 19:36:58 +02:00
ASSERT_EQUALS ( " [test.cpp:6]: (error) Width 5 given in format string (no. 1) is larger than destination buffer 'output[5]', use %4s to prevent overflowing it. \n " , errout . str ( ) ) ;
2012-06-23 07:52:52 +02:00
check ( " void foo() { \n "
" char input[10]; \n "
" char output[5]; \n "
" sscanf(input, \" %s \" , output); \n "
" sscanf(input, \" %3s \" , output); \n "
" sscanf(input, \" %4s \" , output); \n "
" sscanf(input, \" %5s \" , output); \n "
" } " , true ) ;
2012-07-13 19:36:58 +02:00
ASSERT_EQUALS ( " [test.cpp:5]: (warning, inconclusive) Width 3 given in format string (no. 1) is smaller than destination buffer 'output[5]'. \n "
" [test.cpp:7]: (error) Width 5 given in format string (no. 1) is larger than destination buffer 'output[5]', use %4s to prevent overflowing it. \n "
2016-05-26 21:10:50 +02:00
" [test.cpp:4]: (warning) sscanf() without field width limits can crash with huge input data. \n " , errout . str ( ) ) ;
2012-09-10 16:23:00 +02:00
check ( " void foo() { \n "
" const size_t BUFLENGTH(2048); \n "
" typedef char bufT[BUFLENGTH]; \n "
" bufT line= {0}; \n "
" bufT projectId= {0}; \n "
" const int scanrc=sscanf(line, \" Project( \\ \" {%36s} \\ \" ) \" , projectId); \n "
" sscanf(input, \" %5s \" , output); \n "
" } " , true ) ;
2020-06-14 22:57:50 +02:00
ASSERT_EQUALS ( " [test.cpp:6]: (warning, inconclusive) Width 36 given in format string (no. 1) is smaller than destination buffer 'projectId[2048]'. \n " , errout . str ( ) ) ;
2013-09-22 06:56:31 +02:00
2017-10-16 16:53:46 +02:00
check ( " void foo(unsigned int i) { \n "
" scanf( \" %h \" , &i); \n "
" scanf( \" %hh \" , &i); \n "
" scanf( \" %l \" , &i); \n "
" scanf( \" %ll \" , &i); \n "
" scanf( \" %j \" , &i); \n "
" scanf( \" %z \" , &i); \n "
" scanf( \" %t \" , &i); \n "
" scanf( \" %L \" , &i); \n "
" scanf( \" %I \" , &i); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) 'h' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:3]: (warning) 'hh' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:4]: (warning) 'l' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:5]: (warning) 'll' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:6]: (warning) 'j' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:7]: (warning) 'z' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:8]: (warning) 't' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:9]: (warning) 'L' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:10]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n " , errout . str ( ) ) ;
2017-10-20 20:46:24 +02:00
// Unrecognized (and non-existent in standard library) specifiers.
// Perhaps should emit warnings
TEST_SCANF_NOWARN ( " %jb " , " intmax_t " , " intmax_t " ) ;
TEST_SCANF_NOWARN ( " %jw " , " uintmax_t " , " uintmax_t " ) ;
TEST_SCANF_NOWARN ( " %zr " , " size_t " , " size_t " ) ;
TEST_SCANF_NOWARN ( " %tm " , " ptrdiff_t " , " ptrdiff_t " ) ;
TEST_SCANF_NOWARN ( " %La " , " long double " , " long double " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_NOWARN_CPP ( " %zv " , " std::size_t " , " std::size_t " ) ;
TEST_SCANF_NOWARN_CPP ( " %tp " , " std::ptrdiff_t " , " std::ptrdiff_t " ) ;
2017-10-20 20:46:24 +02:00
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %u " , " unsigned int " , " bool " ) ;
TEST_SCANF_WARN ( " %u " , " unsigned int " , " char " ) ;
TEST_SCANF_WARN ( " %u " , " unsigned int " , " signed char " ) ;
TEST_SCANF_WARN ( " %u " , " unsigned int " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %u " , " unsigned int " , " signed short " ) ;
TEST_SCANF_WARN ( " %u " , " unsigned int " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %u " , " unsigned int " , " signed int " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_NOWARN ( " %u " , " unsigned int " , " unsigned int " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %u " , " unsigned int " , " signed long " ) ;
TEST_SCANF_WARN ( " %u " , " unsigned int " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %u " , " unsigned int " , " signed long long " ) ;
TEST_SCANF_WARN ( " %u " , " unsigned int " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %u " , " unsigned int " , " float " ) ;
TEST_SCANF_WARN ( " %u " , " unsigned int " , " double " ) ;
TEST_SCANF_WARN ( " %u " , " unsigned int " , " long double " ) ;
TEST_SCANF_WARN ( " %u " , " unsigned int " , " void * " ) ;
TEST_SCANF_WARN_AKA ( " %u " , " unsigned int " , " size_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %u " , " unsigned int " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %u " , " unsigned int " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
2017-11-06 20:04:59 +01:00
TEST_SCANF_WARN_AKA ( " %u " , " unsigned int " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %u " , " unsigned int " , " intmax_t " , " signed long " , " signed long long " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN_AKA ( " %u " , " unsigned int " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-08 16:13:45 +01:00
TEST_SCANF_WARN_AKA ( " %u " , " unsigned int " , " intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %u " , " unsigned int " , " uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %u " , " unsigned int " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %u " , " unsigned int " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %u " , " unsigned int " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %u " , " unsigned int " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %u " , " unsigned int " , " std::uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %u " , " unsigned int " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %u " , " unsigned int " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 13:49:17 +01:00
2017-10-09 17:50:24 +02:00
check ( " void foo() { \n "
" scanf( \" %u \" , \" s3 \" ); \n "
" scanf( \" %u \" , L \" s5W \" ); \n "
" } " , true ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %u in format string (no. 1) requires 'unsigned int *' but the argument type is 'const char *'. \n "
" [test.cpp:3]: (warning) %u in format string (no. 1) requires 'unsigned int *' but the argument type is 'const wchar_t *'. \n " , errout . str ( ) ) ;
2017-10-23 22:35:32 +02:00
check ( " void foo(long l) { \n "
" scanf( \" %u \" , l); \n "
" } " , true ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %u in format string (no. 1) requires 'unsigned int *' but the argument type is 'signed long'. \n " , errout . str ( ) ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %lu " , " unsigned long " , " bool " ) ;
TEST_SCANF_WARN ( " %lu " , " unsigned long " , " char " ) ;
TEST_SCANF_WARN ( " %lu " , " unsigned long " , " signed char " ) ;
TEST_SCANF_WARN ( " %lu " , " unsigned long " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %lu " , " unsigned long " , " signed short " ) ;
TEST_SCANF_WARN ( " %lu " , " unsigned long " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %lu " , " unsigned long " , " signed int " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN ( " %lu " , " unsigned long " , " unsigned int " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %lu " , " unsigned long " , " signed long " ) ;
TEST_SCANF_NOWARN ( " %lu " , " unsigned long " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %lu " , " unsigned long " , " signed long long " ) ;
TEST_SCANF_WARN ( " %lu " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %lu " , " unsigned long " , " float " ) ;
TEST_SCANF_WARN ( " %lu " , " unsigned long " , " double " ) ;
TEST_SCANF_WARN ( " %lu " , " unsigned long " , " long double " ) ;
TEST_SCANF_WARN ( " %lu " , " unsigned long " , " void * " ) ;
TEST_SCANF_WARN_AKA ( " %lu " , " unsigned long " , " size_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %lu " , " unsigned long " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %lu " , " unsigned long " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
2017-11-09 12:43:09 +01:00
TEST_SCANF_WARN_AKA ( " %lu " , " unsigned long " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %lu " , " unsigned long " , " intmax_t " , " signed long " , " signed long long " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN_AKA ( " %lu " , " unsigned long " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-08 16:13:45 +01:00
TEST_SCANF_WARN_AKA ( " %lu " , " unsigned long " , " intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_WIN64 ( " %lu " , " unsigned long " , " uintptr_t " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %lu " , " unsigned long " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %lu " , " unsigned long " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %lu " , " unsigned long " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %lu " , " unsigned long " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %lu " , " unsigned long " , " std::uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %lu " , " unsigned long " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP_WIN64 ( " %lu " , " unsigned long " , " std::uintptr_t " , " unsigned long long " ) ;
2016-01-31 13:49:17 +01:00
2017-10-13 17:36:12 +02:00
TEST_SCANF_WARN ( " %lx " , " unsigned long " , " bool " ) ;
TEST_SCANF_WARN ( " %lx " , " unsigned long " , " char " ) ;
2017-11-06 21:13:48 +01:00
TEST_SCANF_WARN ( " %lx " , " unsigned long " , " signed char " ) ;
TEST_SCANF_WARN ( " %lx " , " unsigned long " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %lx " , " unsigned long " , " signed short " ) ;
TEST_SCANF_WARN ( " %lx " , " unsigned long " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %lx " , " unsigned long " , " signed int " ) ;
2017-11-09 15:57:03 +01:00
TEST_SCANF_WARN ( " %lx " , " unsigned long " , " unsigned int " ) ;
2017-10-25 20:22:17 +02:00
TEST_SCANF_WARN ( " %lx " , " unsigned long " , " signed long " ) ;
2017-10-13 17:36:12 +02:00
TEST_SCANF_NOWARN ( " %lx " , " unsigned long " , " unsigned long " ) ;
2017-11-06 21:13:48 +01:00
TEST_SCANF_WARN ( " %lx " , " unsigned long " , " signed long long " ) ;
TEST_SCANF_WARN ( " %lx " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %lx " , " unsigned long " , " float " ) ;
TEST_SCANF_WARN ( " %lx " , " unsigned long " , " double " ) ;
TEST_SCANF_WARN ( " %lx " , " unsigned long " , " long double " ) ;
2017-10-13 17:36:12 +02:00
TEST_SCANF_WARN ( " %lx " , " unsigned long " , " void * " ) ;
TEST_SCANF_WARN_AKA ( " %lx " , " unsigned long " , " size_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-06 21:13:48 +01:00
TEST_SCANF_WARN_AKA ( " %lx " , " unsigned long " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %lx " , " unsigned long " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
2017-11-09 12:15:02 +01:00
TEST_SCANF_WARN_AKA ( " %lx " , " unsigned long " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-06 21:13:48 +01:00
TEST_SCANF_WARN_AKA ( " %lx " , " unsigned long " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %lx " , " unsigned long " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-08 16:13:45 +01:00
TEST_SCANF_WARN_AKA ( " %lx " , " unsigned long " , " intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_WIN64 ( " %lx " , " unsigned long " , " uintptr_t " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %lx " , " unsigned long " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %lx " , " unsigned long " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %lx " , " unsigned long " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %lx " , " unsigned long " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %lx " , " unsigned long " , " std::uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %lx " , " unsigned long " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP_WIN64 ( " %lx " , " unsigned long " , " std::uintptr_t " , " unsigned long long " ) ;
2017-10-13 17:36:12 +02:00
TEST_SCANF_WARN ( " %ld " , " long " , " bool " ) ;
TEST_SCANF_WARN ( " %ld " , " long " , " char " ) ;
TEST_SCANF_NOWARN ( " %ld " , " long " , " signed long " ) ;
TEST_SCANF_WARN ( " %ld " , " long " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %ld " , " long " , " void * " ) ;
TEST_SCANF_WARN_AKA ( " %ld " , " long " , " size_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-20 20:34:31 +01:00
TEST_SCANF_WARN_AKA ( " %ld " , " long " , " intmax_t " , " signed long " , " signed long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %ld " , " long " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %ld " , " long " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP_WIN64 ( " %ld " , " long " , " std::intptr_t " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %ld " , " long " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-10-13 17:36:12 +02:00
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %llu " , " unsigned long long " , " bool " ) ;
TEST_SCANF_WARN ( " %llu " , " unsigned long long " , " char " ) ;
TEST_SCANF_WARN ( " %llu " , " unsigned long long " , " signed char " ) ;
TEST_SCANF_WARN ( " %llu " , " unsigned long long " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %llu " , " unsigned long long " , " signed short " ) ;
TEST_SCANF_WARN ( " %llu " , " unsigned long long " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %llu " , " unsigned long long " , " signed int " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN ( " %llu " , " unsigned long long " , " unsigned int " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %llu " , " unsigned long long " , " signed long " ) ;
TEST_SCANF_WARN ( " %llu " , " unsigned long long " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %llu " , " unsigned long long " , " signed long long " ) ;
TEST_SCANF_NOWARN ( " %llu " , " unsigned long long " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %llu " , " unsigned long long " , " float " ) ;
TEST_SCANF_WARN ( " %llu " , " unsigned long long " , " double " ) ;
TEST_SCANF_WARN ( " %llu " , " unsigned long long " , " long double " ) ;
TEST_SCANF_WARN ( " %llu " , " unsigned long long " , " void * " ) ;
TEST_SCANF_WARN_AKA ( " %llu " , " unsigned long long " , " size_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %llu " , " unsigned long long " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %llu " , " unsigned long long " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
2017-11-08 22:26:07 +01:00
TEST_SCANF_WARN_AKA ( " %llu " , " unsigned long long " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %llu " , " unsigned long long " , " intmax_t " , " signed long " , " signed long long " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN_AKA ( " %llu " , " unsigned long long " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-08 16:13:45 +01:00
TEST_SCANF_WARN_AKA ( " %llu " , " unsigned long long " , " intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_WIN32 ( " %llu " , " unsigned long long " , " uintptr_t " , " unsigned long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %llu " , " unsigned long long " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %llu " , " unsigned long long " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %llu " , " unsigned long long " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %llu " , " unsigned long long " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %llu " , " unsigned long long " , " std::uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %llu " , " unsigned long long " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP_WIN32 ( " %llu " , " unsigned long long " , " std::uintptr_t " , " unsigned long " ) ;
2016-01-31 13:49:17 +01:00
2017-10-13 17:36:12 +02:00
TEST_SCANF_WARN ( " %llx " , " unsigned long long " , " bool " ) ;
TEST_SCANF_WARN ( " %llx " , " unsigned long long " , " char " ) ;
2017-11-07 22:05:21 +01:00
TEST_SCANF_WARN ( " %llx " , " unsigned long long " , " signed char " ) ;
TEST_SCANF_WARN ( " %llx " , " unsigned long long " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %llx " , " unsigned long long " , " signed short " ) ;
TEST_SCANF_WARN ( " %llx " , " unsigned long long " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %llx " , " unsigned long long " , " signed int " ) ;
TEST_SCANF_WARN ( " %llx " , " unsigned long long " , " unsigned int " ) ;
TEST_SCANF_WARN ( " %llx " , " unsigned long long " , " signed long " ) ;
TEST_SCANF_WARN ( " %llx " , " unsigned long long " , " unsigned long " ) ;
2017-10-25 20:22:17 +02:00
TEST_SCANF_WARN ( " %llx " , " unsigned long long " , " signed long long " ) ;
2017-10-13 17:36:12 +02:00
TEST_SCANF_NOWARN ( " %llx " , " unsigned long long " , " unsigned long long " ) ;
2017-11-07 22:05:21 +01:00
TEST_SCANF_WARN ( " %llx " , " unsigned long long " , " float " ) ;
TEST_SCANF_WARN ( " %llx " , " unsigned long long " , " double " ) ;
TEST_SCANF_WARN ( " %llx " , " unsigned long long " , " long double " ) ;
2017-10-13 17:36:12 +02:00
TEST_SCANF_WARN ( " %llx " , " unsigned long long " , " void * " ) ;
TEST_SCANF_WARN_AKA ( " %llx " , " unsigned long long " , " size_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-07 22:05:21 +01:00
TEST_SCANF_WARN_AKA ( " %llx " , " unsigned long long " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %llx " , " unsigned long long " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %llx " , " unsigned long long " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA ( " %llx " , " unsigned long long " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %llx " , " unsigned long long " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-08 16:13:45 +01:00
TEST_SCANF_WARN_AKA ( " %llx " , " unsigned long long " , " intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_WIN32 ( " %llx " , " unsigned long long " , " uintptr_t " , " unsigned long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %llx " , " unsigned long long " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %llx " , " unsigned long long " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %llx " , " unsigned long long " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %llx " , " unsigned long long " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %llx " , " unsigned long long " , " std::uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %llx " , " unsigned long long " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP_WIN32 ( " %llx " , " unsigned long long " , " std::uintptr_t " , " unsigned long " ) ;
2017-10-13 17:36:12 +02:00
TEST_SCANF_WARN ( " %lld " , " long long " , " bool " ) ;
TEST_SCANF_WARN ( " %lld " , " long long " , " char " ) ;
TEST_SCANF_NOWARN ( " %lld " , " long long " , " long long " ) ;
TEST_SCANF_WARN ( " %lld " , " long long " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %lld " , " long long " , " void * " ) ;
TEST_SCANF_WARN_AKA ( " %lld " , " long long " , " size_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-20 20:34:31 +01:00
TEST_SCANF_WARN_AKA ( " %lld " , " long long " , " intmax_t " , " signed long " , " signed long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %lld " , " long long " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %lld " , " long long " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP_WIN32 ( " %lld " , " long long " , " std::intptr_t " , " signed long " ) ;
2017-10-13 17:36:12 +02:00
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %hu " , " unsigned short " , " bool " ) ;
TEST_SCANF_WARN ( " %hu " , " unsigned short " , " char " ) ;
TEST_SCANF_WARN ( " %hu " , " unsigned short " , " signed char " ) ;
TEST_SCANF_WARN ( " %hu " , " unsigned short " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %hu " , " unsigned short " , " signed short " ) ;
TEST_SCANF_NOWARN ( " %hu " , " unsigned short " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %hu " , " unsigned short " , " signed int " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN ( " %hu " , " unsigned short " , " unsigned int " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %hu " , " unsigned short " , " signed long " ) ;
TEST_SCANF_WARN ( " %hu " , " unsigned short " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %hu " , " unsigned short " , " signed long long " ) ;
TEST_SCANF_WARN ( " %hu " , " unsigned short " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %hu " , " unsigned short " , " float " ) ;
TEST_SCANF_WARN ( " %hu " , " unsigned short " , " double " ) ;
TEST_SCANF_WARN ( " %hu " , " unsigned short " , " long double " ) ;
TEST_SCANF_WARN ( " %hu " , " unsigned short " , " void * " ) ;
TEST_SCANF_WARN_AKA ( " %hu " , " unsigned short " , " size_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %hu " , " unsigned short " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %hu " , " unsigned short " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
2017-11-06 20:04:59 +01:00
TEST_SCANF_WARN_AKA ( " %hu " , " unsigned short " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %hu " , " unsigned short " , " intmax_t " , " signed long " , " signed long long " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN_AKA ( " %hu " , " unsigned short " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %hu " , " unsigned short " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %hu " , " unsigned short " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %hu " , " unsigned short " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %hu " , " unsigned short " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %hu " , " unsigned short " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 13:49:17 +01:00
2017-10-13 17:36:12 +02:00
TEST_SCANF_WARN ( " %hx " , " unsigned short " , " bool " ) ;
TEST_SCANF_WARN ( " %hx " , " unsigned short " , " char " ) ;
2017-11-06 21:13:48 +01:00
TEST_SCANF_WARN ( " %hx " , " unsigned short " , " signed char " ) ;
TEST_SCANF_WARN ( " %hx " , " unsigned short " , " unsigned char " ) ;
2017-10-25 20:22:17 +02:00
TEST_SCANF_WARN ( " %hx " , " unsigned short " , " signed short " ) ;
2017-10-13 17:36:12 +02:00
TEST_SCANF_NOWARN ( " %hx " , " unsigned short " , " unsigned short " ) ;
2017-11-06 21:13:48 +01:00
TEST_SCANF_WARN ( " %hx " , " unsigned short " , " signed int " ) ;
TEST_SCANF_WARN ( " %hx " , " unsigned short " , " unsigned int " ) ;
TEST_SCANF_WARN ( " %hx " , " unsigned short " , " signed long " ) ;
TEST_SCANF_WARN ( " %hx " , " unsigned short " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %hx " , " unsigned short " , " signed long long " ) ;
TEST_SCANF_WARN ( " %hx " , " unsigned short " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %hx " , " unsigned short " , " float " ) ;
TEST_SCANF_WARN ( " %hx " , " unsigned short " , " double " ) ;
TEST_SCANF_WARN ( " %hx " , " unsigned short " , " long double " ) ;
2017-10-13 17:36:12 +02:00
TEST_SCANF_WARN ( " %hx " , " unsigned short " , " void * " ) ;
2017-11-06 21:13:48 +01:00
TEST_SCANF_WARN_AKA ( " %hx " , " unsigned short " , " size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA ( " %hx " , " unsigned short " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %hx " , " unsigned short " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %hx " , " unsigned short " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA ( " %hx " , " unsigned short " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %hx " , " unsigned short " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %hx " , " unsigned short " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %hx " , " unsigned short " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %hx " , " unsigned short " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %hx " , " unsigned short " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %hx " , " unsigned short " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-10-13 17:36:12 +02:00
2017-10-16 17:07:08 +02:00
TEST_SCANF_WARN ( " %hd " , " short " , " bool " ) ;
TEST_SCANF_WARN ( " %hd " , " short " , " char " ) ;
TEST_SCANF_WARN ( " %hd " , " short " , " signed char " ) ;
TEST_SCANF_WARN ( " %hd " , " short " , " unsigned char " ) ;
TEST_SCANF_NOWARN ( " %hd " , " short " , " signed short " ) ;
TEST_SCANF_WARN ( " %hd " , " short " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %hd " , " short " , " signed int " ) ;
TEST_SCANF_WARN ( " %hd " , " short " , " unsigned int " ) ;
TEST_SCANF_WARN ( " %hd " , " short " , " signed long " ) ;
TEST_SCANF_WARN ( " %hd " , " short " , " void * " ) ;
TEST_SCANF_WARN_AKA ( " %hd " , " short " , " size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA ( " %hd " , " short " , " ssize_t " , " signed long " , " signed long long " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %hhu " , " unsigned char " , " bool " ) ;
TEST_SCANF_WARN ( " %hhu " , " unsigned char " , " char " ) ;
TEST_SCANF_WARN ( " %hhu " , " unsigned char " , " signed char " ) ;
TEST_SCANF_NOWARN ( " %hhu " , " unsigned char " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %hhu " , " unsigned char " , " signed short " ) ;
TEST_SCANF_WARN ( " %hhu " , " unsigned char " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %hhu " , " unsigned char " , " signed int " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN ( " %hhu " , " unsigned char " , " unsigned int " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %hhu " , " unsigned char " , " signed long " ) ;
TEST_SCANF_WARN ( " %hhu " , " unsigned char " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %hhu " , " unsigned char " , " signed long long " ) ;
TEST_SCANF_WARN ( " %hhu " , " unsigned char " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %hhu " , " unsigned char " , " float " ) ;
TEST_SCANF_WARN ( " %hhu " , " unsigned char " , " double " ) ;
TEST_SCANF_WARN ( " %hhu " , " unsigned char " , " long double " ) ;
TEST_SCANF_WARN ( " %hhu " , " unsigned char " , " void * " ) ;
TEST_SCANF_WARN_AKA ( " %hhu " , " unsigned char " , " size_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %hhu " , " unsigned char " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %hhu " , " unsigned char " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
2017-11-06 20:04:59 +01:00
TEST_SCANF_WARN_AKA ( " %hhu " , " unsigned char " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %hhu " , " unsigned char " , " intmax_t " , " signed long " , " signed long long " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN_AKA ( " %hhu " , " unsigned char " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %hhu " , " unsigned char " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %hhu " , " unsigned char " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %hhu " , " unsigned char " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %hhu " , " unsigned char " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %hhu " , " unsigned char " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 13:49:17 +01:00
2017-10-13 17:36:12 +02:00
TEST_SCANF_WARN ( " %hhx " , " unsigned char " , " bool " ) ;
2017-10-25 20:22:17 +02:00
TEST_SCANF_WARN ( " %hhx " , " unsigned char " , " char " ) ;
TEST_SCANF_WARN ( " %hhx " , " unsigned char " , " signed char " ) ;
2017-10-13 17:36:12 +02:00
TEST_SCANF_NOWARN ( " %hhx " , " unsigned char " , " unsigned char " ) ;
2017-11-06 21:13:48 +01:00
TEST_SCANF_WARN ( " %hhx " , " unsigned char " , " signed short " ) ;
TEST_SCANF_WARN ( " %hhx " , " unsigned char " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %hhx " , " unsigned char " , " signed int " ) ;
TEST_SCANF_WARN ( " %hhx " , " unsigned char " , " unsigned int " ) ;
TEST_SCANF_WARN ( " %hhx " , " unsigned char " , " signed long " ) ;
TEST_SCANF_WARN ( " %hhx " , " unsigned char " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %hhx " , " unsigned char " , " signed long long " ) ;
TEST_SCANF_WARN ( " %hhx " , " unsigned char " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %hhx " , " unsigned char " , " float " ) ;
TEST_SCANF_WARN ( " %hhx " , " unsigned char " , " double " ) ;
TEST_SCANF_WARN ( " %hhx " , " unsigned char " , " long double " ) ;
2017-10-13 17:36:12 +02:00
TEST_SCANF_WARN ( " %hhx " , " unsigned char " , " void * " ) ;
2017-11-06 21:13:48 +01:00
TEST_SCANF_WARN_AKA ( " %hhx " , " unsigned char " , " size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA ( " %hhx " , " unsigned char " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %hhx " , " unsigned char " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %hhx " , " unsigned char " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA ( " %hhx " , " unsigned char " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %hhx " , " unsigned char " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %hhx " , " unsigned char " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %hhx " , " unsigned char " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %hhx " , " unsigned char " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %hhx " , " unsigned char " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %hhx " , " unsigned char " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-10-13 17:36:12 +02:00
2017-10-16 17:07:08 +02:00
TEST_SCANF_WARN ( " %hhd " , " char " , " bool " ) ;
TEST_SCANF_NOWARN ( " %hhd " , " char " , " char " ) ;
TEST_SCANF_NOWARN ( " %hhd " , " char " , " signed char " ) ;
TEST_SCANF_WARN ( " %hhd " , " char " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %hhd " , " char " , " signed short " ) ;
TEST_SCANF_WARN ( " %hhd " , " char " , " void * " ) ;
TEST_SCANF_WARN_AKA ( " %hhd " , " char " , " size_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %Lu " , " unsigned long long " , " bool " ) ;
TEST_SCANF_WARN ( " %Lu " , " unsigned long long " , " char " ) ;
TEST_SCANF_WARN ( " %Lu " , " unsigned long long " , " signed char " ) ;
TEST_SCANF_WARN ( " %Lu " , " unsigned long long " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %Lu " , " unsigned long long " , " signed short " ) ;
TEST_SCANF_WARN ( " %Lu " , " unsigned long long " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %Lu " , " unsigned long long " , " signed int " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN ( " %Lu " , " unsigned long long " , " unsigned int " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %Lu " , " unsigned long long " , " signed long " ) ;
TEST_SCANF_WARN ( " %Lu " , " unsigned long long " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %Lu " , " unsigned long long " , " signed long long " ) ;
TEST_SCANF_NOWARN ( " %Lu " , " unsigned long long " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %Lu " , " unsigned long long " , " float " ) ;
TEST_SCANF_WARN ( " %Lu " , " unsigned long long " , " double " ) ;
TEST_SCANF_WARN ( " %Lu " , " unsigned long long " , " long double " ) ;
TEST_SCANF_WARN ( " %Lu " , " unsigned long long " , " void * " ) ;
TEST_SCANF_WARN_AKA ( " %Lu " , " unsigned long long " , " size_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %Lu " , " unsigned long long " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %Lu " , " unsigned long long " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
2017-11-06 20:04:59 +01:00
TEST_SCANF_WARN_AKA_WIN32 ( " %Lu " , " unsigned long long " , " unsigned ptrdiff_t " , " unsigned long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %Lu " , " unsigned long long " , " intmax_t " , " signed long " , " signed long long " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN_AKA ( " %Lu " , " unsigned long long " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-08 16:13:45 +01:00
TEST_SCANF_WARN_AKA ( " %Lu " , " unsigned long long " , " intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_WIN32 ( " %Lu " , " unsigned long long " , " uintptr_t " , " unsigned long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %Lu " , " unsigned long long " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Lu " , " unsigned long long " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Lu " , " unsigned long long " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Lu " , " unsigned long long " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Lu " , " unsigned long long " , " std::uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Lu " , " unsigned long long " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP_WIN32 ( " %Lu " , " unsigned long long " , " std::uintptr_t " , " unsigned long " ) ;
2016-01-31 13:49:17 +01:00
2017-10-13 17:36:12 +02:00
TEST_SCANF_WARN ( " %Lx " , " unsigned long long " , " bool " ) ;
2017-11-07 22:05:21 +01:00
TEST_SCANF_WARN ( " %Lx " , " unsigned long long " , " char " ) ;
TEST_SCANF_WARN ( " %Lx " , " unsigned long long " , " signed char " ) ;
TEST_SCANF_WARN ( " %Lx " , " unsigned long long " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %Lx " , " unsigned long long " , " signed short " ) ;
TEST_SCANF_WARN ( " %Lx " , " unsigned long long " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %Lx " , " unsigned long long " , " signed int " ) ;
TEST_SCANF_WARN ( " %Lx " , " unsigned long long " , " unsigned int " ) ;
TEST_SCANF_WARN ( " %Lx " , " unsigned long long " , " signed long " ) ;
TEST_SCANF_WARN ( " %Lx " , " unsigned long long " , " unsigned long " ) ;
2017-10-25 20:22:17 +02:00
TEST_SCANF_WARN ( " %Lx " , " unsigned long long " , " signed long long " ) ;
2017-10-13 17:36:12 +02:00
TEST_SCANF_NOWARN ( " %Lx " , " unsigned long long " , " unsigned long long " ) ;
2017-11-07 22:05:21 +01:00
TEST_SCANF_WARN ( " %Lx " , " unsigned long long " , " float " ) ;
TEST_SCANF_WARN ( " %Lx " , " unsigned long long " , " double " ) ;
TEST_SCANF_WARN ( " %Lx " , " unsigned long long " , " long double " ) ;
2017-10-13 17:36:12 +02:00
TEST_SCANF_WARN ( " %Lx " , " unsigned long long " , " void * " ) ;
2017-11-08 21:52:49 +01:00
TEST_SCANF_WARN_AKA ( " %Lx " , " unsigned long long " , " size_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-07 22:05:21 +01:00
TEST_SCANF_WARN_AKA ( " %Lx " , " unsigned long long " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %Lx " , " unsigned long long " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_WIN32 ( " %Lx " , " unsigned long long " , " unsigned ptrdiff_t " , " unsigned long " ) ;
TEST_SCANF_WARN_AKA ( " %Lx " , " unsigned long long " , " intmax_t " , " signed long " , " signed long long " ) ;
2017-11-08 21:52:49 +01:00
TEST_SCANF_WARN_AKA ( " %Lx " , " unsigned long long " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-08 16:13:45 +01:00
TEST_SCANF_WARN_AKA ( " %Lx " , " unsigned long long " , " intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_WIN32 ( " %Lx " , " unsigned long long " , " uintptr_t " , " unsigned long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %Lx " , " unsigned long long " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Lx " , " unsigned long long " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Lx " , " unsigned long long " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Lx " , " unsigned long long " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Lx " , " unsigned long long " , " std::uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Lx " , " unsigned long long " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP_WIN32 ( " %Lx " , " unsigned long long " , " std::uintptr_t " , " unsigned long " ) ;
2017-10-13 17:36:12 +02:00
2017-10-12 17:18:38 +02:00
TEST_SCANF_WARN ( " %Ld " , " long long " , " bool " ) ;
TEST_SCANF_WARN ( " %Ld " , " long long " , " char " ) ;
TEST_SCANF_WARN ( " %Ld " , " long long " , " signed char " ) ;
TEST_SCANF_WARN ( " %Ld " , " long long " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %Ld " , " long long " , " signed short " ) ;
TEST_SCANF_WARN ( " %Ld " , " long long " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %Ld " , " long long " , " signed int " ) ;
TEST_SCANF_WARN ( " %Ld " , " long long " , " unsigned int " ) ;
TEST_SCANF_WARN ( " %Ld " , " long long " , " signed long " ) ;
TEST_SCANF_WARN ( " %Ld " , " long long " , " unsigned long " ) ;
TEST_SCANF_NOWARN ( " %Ld " , " long long " , " signed long long " ) ;
TEST_SCANF_WARN ( " %Ld " , " long long " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %Ld " , " long long " , " float " ) ;
TEST_SCANF_WARN ( " %Ld " , " long long " , " double " ) ;
TEST_SCANF_WARN ( " %Ld " , " long long " , " long double " ) ;
TEST_SCANF_WARN ( " %Ld " , " long long " , " void * " ) ;
TEST_SCANF_WARN_AKA ( " %Ld " , " long long " , " size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_WIN32 ( " %Ld " , " long long " , " ssize_t " , " signed long " ) ;
TEST_SCANF_WARN_AKA_WIN32 ( " %Ld " , " long long " , " ptrdiff_t " , " signed long " ) ;
2017-10-26 22:47:11 +02:00
TEST_SCANF_WARN_AKA ( " %Ld " , " long long " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
2017-10-12 17:18:38 +02:00
TEST_SCANF_WARN_AKA_WIN32 ( " %Ld " , " long long " , " intmax_t " , " signed long " ) ;
TEST_SCANF_WARN_AKA ( " %Ld " , " long long " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %Ld " , " long long " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP_WIN32 ( " %Ld " , " long long " , " std::ssize_t " , " signed long " ) ;
TEST_SCANF_WARN_AKA_CPP_WIN32 ( " %Ld " , " long long " , " std::ptrdiff_t " , " signed long " ) ;
TEST_SCANF_WARN_AKA_CPP_WIN32 ( " %Ld " , " long long " , " std::intptr_t " , " signed long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Ld " , " long long " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-10-12 17:18:38 +02:00
check ( " void foo() { \n "
" scanf( \" %Ld \" , \" s3 \" ); \n "
" scanf( \" %Ld \" , L \" s5W \" ); \n "
" } " , true ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %Ld in format string (no. 1) requires 'long long *' but the argument type is 'const char *'. \n "
" [test.cpp:3]: (warning) %Ld in format string (no. 1) requires 'long long *' but the argument type is 'const wchar_t *'. \n " , errout . str ( ) ) ;
2017-10-23 22:35:32 +02:00
check ( " void foo(int i) { \n "
" scanf( \" %Ld \" , i); \n "
" } " , true ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %Ld in format string (no. 1) requires 'long long *' but the argument type is 'signed int'. \n " , errout . str ( ) ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %ju " , " uintmax_t " , " bool " ) ;
TEST_SCANF_WARN ( " %ju " , " uintmax_t " , " char " ) ;
TEST_SCANF_WARN ( " %ju " , " uintmax_t " , " signed char " ) ;
TEST_SCANF_WARN ( " %ju " , " uintmax_t " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %ju " , " uintmax_t " , " signed short " ) ;
TEST_SCANF_WARN ( " %ju " , " uintmax_t " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %ju " , " uintmax_t " , " signed int " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN ( " %ju " , " uintmax_t " , " unsigned int " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %ju " , " uintmax_t " , " signed long " ) ;
TEST_SCANF_WARN ( " %ju " , " uintmax_t " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %ju " , " uintmax_t " , " signed long long " ) ;
TEST_SCANF_WARN ( " %ju " , " uintmax_t " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %ju " , " uintmax_t " , " float " ) ;
TEST_SCANF_WARN ( " %ju " , " uintmax_t " , " double " ) ;
TEST_SCANF_WARN ( " %ju " , " uintmax_t " , " long double " ) ;
TEST_SCANF_WARN ( " %ju " , " uintmax_t " , " void * " ) ;
TEST_SCANF_WARN_AKA ( " %ju " , " uintmax_t " , " size_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %ju " , " uintmax_t " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %ju " , " uintmax_t " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
2017-11-06 20:04:59 +01:00
TEST_SCANF_WARN_AKA ( " %ju " , " uintmax_t " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %ju " , " uintmax_t " , " intmax_t " , " signed long " , " signed long long " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_NOWARN ( " %ju " , " uintmax_t " , " uintmax_t " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %ju " , " uintmax_t " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %ju " , " uintmax_t " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %ju " , " uintmax_t " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %ju " , " uintmax_t " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_NOWARN_CPP ( " %ju " , " uintmax_t " , " std::uintmax_t " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %ju " , " uintmax_t " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %ju " , " uintmax_t " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 13:49:17 +01:00
2017-11-06 22:27:47 +01:00
TEST_SCANF_WARN ( " %jx " , " uintmax_t " , " bool " ) ;
TEST_SCANF_WARN ( " %jx " , " uintmax_t " , " char " ) ;
TEST_SCANF_WARN ( " %jx " , " uintmax_t " , " signed char " ) ;
2017-10-26 22:36:55 +02:00
TEST_SCANF_WARN ( " %jx " , " uintmax_t " , " unsigned char " ) ;
2017-11-06 22:27:47 +01:00
TEST_SCANF_WARN ( " %jx " , " uintmax_t " , " signed short " ) ;
TEST_SCANF_WARN ( " %jx " , " uintmax_t " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %jx " , " uintmax_t " , " signed int " ) ;
TEST_SCANF_WARN ( " %jx " , " uintmax_t " , " unsigned int " ) ;
TEST_SCANF_WARN ( " %jx " , " uintmax_t " , " signed long " ) ;
TEST_SCANF_WARN ( " %jx " , " uintmax_t " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %jx " , " uintmax_t " , " signed long long " ) ;
TEST_SCANF_WARN ( " %jx " , " uintmax_t " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %jx " , " uintmax_t " , " float " ) ;
TEST_SCANF_WARN ( " %jx " , " uintmax_t " , " double " ) ;
2017-10-13 17:36:12 +02:00
TEST_SCANF_WARN ( " %jx " , " uintmax_t " , " long double " ) ;
TEST_SCANF_WARN ( " %jx " , " uintmax_t " , " void * " ) ;
2017-11-06 22:27:47 +01:00
TEST_SCANF_WARN_AKA ( " %jx " , " uintmax_t " , " size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA ( " %jx " , " uintmax_t " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %jx " , " uintmax_t " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %jx " , " uintmax_t " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
2017-10-13 17:36:12 +02:00
TEST_SCANF_WARN_AKA ( " %jx " , " uintmax_t " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_NOWARN ( " %jx " , " uintmax_t " , " uintmax_t " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %jx " , " uintmax_t " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %jx " , " uintmax_t " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %jx " , " uintmax_t " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %jx " , " uintmax_t " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_NOWARN_CPP ( " %jx " , " uintmax_t " , " std::uintmax_t " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %jx " , " uintmax_t " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %jx " , " uintmax_t " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-10-13 17:36:12 +02:00
2017-10-16 17:07:08 +02:00
TEST_SCANF_WARN ( " %jd " , " intmax_t " , " long double " ) ;
TEST_SCANF_WARN ( " %jd " , " intmax_t " , " void * " ) ;
2019-11-20 16:10:56 +01:00
TEST_SCANF_WARN_AKA ( " %jd " , " intmax_t " , " size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA ( " %jd " , " intmax_t " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %jd " , " intmax_t " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %jd " , " intmax_t " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
2017-10-16 17:07:08 +02:00
TEST_SCANF_NOWARN ( " %jd " , " intmax_t " , " intmax_t " ) ;
2017-11-09 17:07:41 +01:00
TEST_SCANF_WARN_AKA ( " %jd " , " intmax_t " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_NOWARN_CPP ( " %jd " , " intmax_t " , " std::intmax_t " ) ;
2017-10-16 17:07:08 +02:00
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %zu " , " size_t " , " bool " ) ;
TEST_SCANF_WARN ( " %zu " , " size_t " , " char " ) ;
TEST_SCANF_WARN ( " %zu " , " size_t " , " signed char " ) ;
TEST_SCANF_WARN ( " %zu " , " size_t " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %zu " , " size_t " , " signed short " ) ;
TEST_SCANF_WARN ( " %zu " , " size_t " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %zu " , " size_t " , " signed int " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN ( " %zu " , " size_t " , " unsigned int " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %zu " , " size_t " , " signed long " ) ;
TEST_SCANF_WARN ( " %zu " , " size_t " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %zu " , " size_t " , " signed long long " ) ;
TEST_SCANF_WARN ( " %zu " , " size_t " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %zu " , " size_t " , " float " ) ;
TEST_SCANF_WARN ( " %zu " , " size_t " , " double " ) ;
TEST_SCANF_WARN ( " %zu " , " size_t " , " long double " ) ;
TEST_SCANF_WARN ( " %zu " , " size_t " , " void * " ) ;
TEST_SCANF_NOWARN ( " %zu " , " size_t " , " size_t " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %zu " , " size_t " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %zu " , " size_t " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
2017-10-26 22:47:11 +02:00
TEST_SCANF_WARN_AKA ( " %zu " , " size_t " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %zu " , " size_t " , " intmax_t " , " signed long " , " signed long long " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN_AKA ( " %zu " , " size_t " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_NOWARN_CPP ( " %zu " , " size_t " , " std::size_t " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %zu " , " size_t " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %zu " , " size_t " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %zu " , " size_t " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %zu " , " size_t " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 13:49:17 +01:00
2017-10-13 17:36:12 +02:00
TEST_SCANF_WARN ( " %zx " , " size_t " , " bool " ) ;
2017-11-06 22:27:47 +01:00
TEST_SCANF_WARN ( " %zx " , " size_t " , " char " ) ;
TEST_SCANF_WARN ( " %zx " , " size_t " , " signed char " ) ;
2017-10-26 22:36:55 +02:00
TEST_SCANF_WARN ( " %zx " , " size_t " , " unsigned char " ) ;
2017-11-06 22:27:47 +01:00
TEST_SCANF_WARN ( " %zx " , " size_t " , " signed short " ) ;
TEST_SCANF_WARN ( " %zx " , " size_t " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %zx " , " size_t " , " signed int " ) ;
TEST_SCANF_WARN ( " %zx " , " size_t " , " unsigned int " ) ;
TEST_SCANF_WARN ( " %zx " , " size_t " , " signed long " ) ;
TEST_SCANF_WARN ( " %zx " , " size_t " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %zx " , " size_t " , " signed long long " ) ;
TEST_SCANF_WARN ( " %zx " , " size_t " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %zx " , " size_t " , " float " ) ;
TEST_SCANF_WARN ( " %zx " , " size_t " , " double " ) ;
TEST_SCANF_WARN ( " %zx " , " size_t " , " long double " ) ;
2017-10-13 17:36:12 +02:00
TEST_SCANF_WARN ( " %zx " , " size_t " , " void * " ) ;
TEST_SCANF_NOWARN ( " %zx " , " size_t " , " size_t " ) ;
TEST_SCANF_WARN_AKA ( " %zx " , " size_t " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %zx " , " size_t " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
2017-11-06 22:27:47 +01:00
TEST_SCANF_WARN_AKA ( " %zx " , " size_t " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA ( " %zx " , " size_t " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %zx " , " size_t " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_NOWARN_CPP ( " %zx " , " size_t " , " std::size_t " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %zx " , " size_t " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %zx " , " size_t " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %zx " , " size_t " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %zx " , " size_t " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-10-13 17:36:12 +02:00
2017-10-24 22:47:04 +02:00
TEST_SCANF_WARN ( " %zd " , " ssize_t " , " bool " ) ;
TEST_SCANF_WARN ( " %zd " , " ssize_t " , " signed short " ) ;
TEST_SCANF_WARN ( " %zd " , " ssize_t " , " void * " ) ;
2017-11-08 11:43:10 +01:00
TEST_SCANF_WARN_AKA ( " %zd " , " ssize_t " , " size_t " , " unsigned long " , " unsigned long long " ) ;
2017-10-24 22:47:04 +02:00
TEST_SCANF_NOWARN ( " %zd " , " ssize_t " , " ssize_t " ) ;
2017-11-08 12:22:03 +01:00
TEST_SCANF_WARN_AKA ( " %zd " , " ssize_t " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
2017-10-24 22:47:04 +02:00
2021-09-05 07:34:22 +02:00
TEST_SCANF_WARN_AKA ( " %zi " , " ssize_t " , " size_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %tu " , " unsigned ptrdiff_t " , " bool " ) ;
TEST_SCANF_WARN ( " %tu " , " unsigned ptrdiff_t " , " char " ) ;
TEST_SCANF_WARN ( " %tu " , " unsigned ptrdiff_t " , " signed char " ) ;
TEST_SCANF_WARN ( " %tu " , " unsigned ptrdiff_t " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %tu " , " unsigned ptrdiff_t " , " signed short " ) ;
TEST_SCANF_WARN ( " %tu " , " unsigned ptrdiff_t " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %tu " , " unsigned ptrdiff_t " , " signed int " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN ( " %tu " , " unsigned ptrdiff_t " , " unsigned int " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %tu " , " unsigned ptrdiff_t " , " signed long " ) ;
TEST_SCANF_WARN ( " %tu " , " unsigned ptrdiff_t " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %tu " , " unsigned ptrdiff_t " , " signed long long " ) ;
TEST_SCANF_WARN ( " %tu " , " unsigned ptrdiff_t " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %tu " , " unsigned ptrdiff_t " , " float " ) ;
TEST_SCANF_WARN ( " %tu " , " unsigned ptrdiff_t " , " double " ) ;
TEST_SCANF_WARN ( " %tu " , " unsigned ptrdiff_t " , " long double " ) ;
TEST_SCANF_WARN ( " %tu " , " unsigned ptrdiff_t " , " void * " ) ;
TEST_SCANF_WARN_AKA ( " %tu " , " unsigned ptrdiff_t " , " size_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %tu " , " unsigned ptrdiff_t " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %tu " , " unsigned ptrdiff_t " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
2017-11-06 20:04:59 +01:00
TEST_SCANF_NOWARN ( " %tu " , " unsigned ptrdiff_t " , " unsigned ptrdiff_t " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %tu " , " unsigned ptrdiff_t " , " intmax_t " , " signed long " , " signed long long " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN_AKA ( " %tu " , " unsigned ptrdiff_t " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %tu " , " unsigned ptrdiff_t " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %tu " , " unsigned ptrdiff_t " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %tu " , " unsigned ptrdiff_t " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %tu " , " unsigned ptrdiff_t " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %tu " , " unsigned ptrdiff_t " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 13:49:17 +01:00
2017-11-06 22:27:47 +01:00
TEST_SCANF_WARN ( " %tx " , " unsigned ptrdiff_t " , " bool " ) ;
TEST_SCANF_WARN ( " %tx " , " unsigned ptrdiff_t " , " char " ) ;
TEST_SCANF_WARN ( " %tx " , " unsigned ptrdiff_t " , " signed char " ) ;
2017-10-26 22:36:55 +02:00
TEST_SCANF_WARN ( " %tx " , " unsigned ptrdiff_t " , " unsigned char " ) ;
2017-11-06 22:27:47 +01:00
TEST_SCANF_WARN ( " %tx " , " unsigned ptrdiff_t " , " signed short " ) ;
TEST_SCANF_WARN ( " %tx " , " unsigned ptrdiff_t " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %tx " , " unsigned ptrdiff_t " , " signed int " ) ;
TEST_SCANF_WARN ( " %tx " , " unsigned ptrdiff_t " , " unsigned int " ) ;
TEST_SCANF_WARN ( " %tx " , " unsigned ptrdiff_t " , " signed long " ) ;
TEST_SCANF_WARN ( " %tx " , " unsigned ptrdiff_t " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %tx " , " unsigned ptrdiff_t " , " signed long long " ) ;
TEST_SCANF_WARN ( " %tx " , " unsigned ptrdiff_t " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %tx " , " unsigned ptrdiff_t " , " float " ) ;
TEST_SCANF_WARN ( " %tx " , " unsigned ptrdiff_t " , " double " ) ;
2017-10-13 17:36:12 +02:00
TEST_SCANF_WARN ( " %tx " , " unsigned ptrdiff_t " , " long double " ) ;
TEST_SCANF_WARN ( " %tx " , " unsigned ptrdiff_t " , " void * " ) ;
2017-11-06 22:27:47 +01:00
TEST_SCANF_WARN_AKA ( " %tx " , " unsigned ptrdiff_t " , " size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA ( " %tx " , " unsigned ptrdiff_t " , " ssize_t " , " signed long " , " signed long long " ) ;
2017-10-25 20:22:17 +02:00
TEST_SCANF_WARN_AKA ( " %tx " , " unsigned ptrdiff_t " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
2017-10-13 17:36:12 +02:00
TEST_SCANF_NOWARN ( " %tx " , " unsigned ptrdiff_t " , " unsigned ptrdiff_t " ) ;
2017-11-06 22:27:47 +01:00
TEST_SCANF_WARN_AKA ( " %tx " , " unsigned ptrdiff_t " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %tx " , " unsigned ptrdiff_t " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %tx " , " unsigned ptrdiff_t " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %tx " , " unsigned ptrdiff_t " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %tx " , " unsigned ptrdiff_t " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %tx " , " unsigned ptrdiff_t " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %tx " , " unsigned ptrdiff_t " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-10-13 17:36:12 +02:00
2017-10-17 17:09:10 +02:00
TEST_SCANF_WARN ( " %td " , " ptrdiff_t " , " long double " ) ;
TEST_SCANF_WARN ( " %td " , " ptrdiff_t " , " void * " ) ;
TEST_SCANF_NOWARN ( " %td " , " ptrdiff_t " , " ptrdiff_t " ) ;
TEST_SCANF_WARN_AKA ( " %td " , " ptrdiff_t " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %td " , " ptrdiff_t " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2017-10-26 22:47:11 +02:00
TEST_SCANF_WARN_AKA ( " %td " , " ptrdiff_t " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
2017-10-17 17:09:10 +02:00
2017-11-08 06:06:05 +01:00
TEST_SCANF_WARN ( " %Iu " , " size_t " , " bool " ) ;
TEST_SCANF_WARN ( " %Iu " , " size_t " , " char " ) ;
TEST_SCANF_WARN ( " %Iu " , " size_t " , " signed char " ) ;
TEST_SCANF_WARN ( " %Iu " , " size_t " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %Iu " , " size_t " , " signed short " ) ;
TEST_SCANF_WARN ( " %Iu " , " size_t " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %Iu " , " size_t " , " signed int " ) ;
TEST_SCANF_WARN ( " %Iu " , " size_t " , " unsigned int " ) ;
TEST_SCANF_WARN ( " %Iu " , " size_t " , " signed long " ) ;
TEST_SCANF_WARN ( " %Iu " , " size_t " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %Iu " , " size_t " , " signed long long " ) ;
TEST_SCANF_WARN ( " %Iu " , " size_t " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %Iu " , " size_t " , " float " ) ;
TEST_SCANF_WARN ( " %Iu " , " size_t " , " double " ) ;
TEST_SCANF_WARN ( " %Iu " , " size_t " , " long double " ) ;
TEST_SCANF_WARN ( " %Iu " , " size_t " , " void * " ) ;
TEST_SCANF_NOWARN ( " %Iu " , " size_t " , " size_t " ) ;
TEST_SCANF_WARN_AKA ( " %Iu " , " size_t " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %Iu " , " size_t " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %Iu " , " size_t " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA ( " %Iu " , " size_t " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %Iu " , " size_t " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-08 16:13:45 +01:00
TEST_SCANF_WARN_AKA ( " %Iu " , " size_t " , " intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %Iu " , " size_t " , " uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_NOWARN_CPP ( " %Iu " , " size_t " , " std::size_t " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Iu " , " size_t " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Iu " , " size_t " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Iu " , " size_t " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Iu " , " size_t " , " std::uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Iu " , " size_t " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Iu " , " size_t " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-08 06:06:05 +01:00
TEST_SCANF_WARN ( " %Ix " , " size_t " , " bool " ) ;
TEST_SCANF_WARN ( " %Ix " , " size_t " , " char " ) ;
TEST_SCANF_WARN ( " %Ix " , " size_t " , " signed char " ) ;
TEST_SCANF_WARN ( " %Ix " , " size_t " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %Ix " , " size_t " , " signed short " ) ;
TEST_SCANF_WARN ( " %Ix " , " size_t " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %Ix " , " size_t " , " signed int " ) ;
TEST_SCANF_WARN ( " %Ix " , " size_t " , " unsigned int " ) ;
TEST_SCANF_WARN ( " %Ix " , " size_t " , " signed long " ) ;
TEST_SCANF_WARN ( " %Ix " , " size_t " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %Ix " , " size_t " , " signed long long " ) ;
TEST_SCANF_WARN ( " %Ix " , " size_t " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %Ix " , " size_t " , " float " ) ;
TEST_SCANF_WARN ( " %Ix " , " size_t " , " double " ) ;
TEST_SCANF_WARN ( " %Ix " , " size_t " , " long double " ) ;
TEST_SCANF_WARN ( " %Ix " , " size_t " , " void * " ) ;
TEST_SCANF_NOWARN ( " %Ix " , " size_t " , " size_t " ) ;
TEST_SCANF_WARN_AKA ( " %Ix " , " size_t " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %Ix " , " size_t " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
2017-11-08 13:06:51 +01:00
TEST_SCANF_WARN_AKA ( " %Ix " , " size_t " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-08 06:06:05 +01:00
TEST_SCANF_WARN_AKA ( " %Ix " , " size_t " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %Ix " , " size_t " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-08 16:13:45 +01:00
TEST_SCANF_WARN_AKA ( " %Ix " , " size_t " , " intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %Ix " , " size_t " , " uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_NOWARN_CPP ( " %Ix " , " size_t " , " std::size_t " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Ix " , " size_t " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Ix " , " size_t " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Ix " , " size_t " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Ix " , " size_t " , " std::uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Ix " , " size_t " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Ix " , " size_t " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-08 06:06:05 +01:00
2017-10-12 17:18:38 +02:00
TEST_SCANF_WARN ( " %Id " , " ptrdiff_t " , " bool " ) ;
TEST_SCANF_WARN ( " %Id " , " ptrdiff_t " , " char " ) ;
TEST_SCANF_WARN ( " %Id " , " ptrdiff_t " , " signed char " ) ;
TEST_SCANF_WARN ( " %Id " , " ptrdiff_t " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %Id " , " ptrdiff_t " , " signed short " ) ;
TEST_SCANF_WARN ( " %Id " , " ptrdiff_t " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %Id " , " ptrdiff_t " , " signed int " ) ;
2017-10-10 16:27:33 +02:00
TEST_SCANF_WARN ( " %Id " , " ptrdiff_t " , " unsigned int " ) ;
2017-10-12 17:18:38 +02:00
TEST_SCANF_WARN ( " %Id " , " ptrdiff_t " , " signed long " ) ;
TEST_SCANF_WARN ( " %Id " , " ptrdiff_t " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %Id " , " ptrdiff_t " , " signed long long " ) ;
TEST_SCANF_WARN ( " %Id " , " ptrdiff_t " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %Id " , " ptrdiff_t " , " float " ) ;
TEST_SCANF_WARN ( " %Id " , " ptrdiff_t " , " double " ) ;
TEST_SCANF_WARN ( " %Id " , " ptrdiff_t " , " long double " ) ;
2017-11-07 21:43:30 +01:00
TEST_SCANF_WARN ( " %Id " , " ptrdiff_t " , " void * " ) ;
2017-10-12 17:18:38 +02:00
TEST_SCANF_WARN_AKA ( " %Id " , " ptrdiff_t " , " size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA ( " %Id " , " ptrdiff_t " , " ssize_t " , " signed long " , " signed long long " ) ;
2017-11-06 19:01:34 +01:00
TEST_SCANF_NOWARN ( " %Id " , " ptrdiff_t " , " ptrdiff_t " ) ;
2017-11-06 20:04:59 +01:00
TEST_SCANF_WARN_AKA ( " %Id " , " ptrdiff_t " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
2017-10-12 17:18:38 +02:00
TEST_SCANF_WARN_AKA ( " %Id " , " ptrdiff_t " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %Id " , " ptrdiff_t " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %Id " , " ptrdiff_t " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Id " , " ptrdiff_t " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_NOWARN_CPP ( " %Id " , " ptrdiff_t " , " std::ptrdiff_t " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Id " , " ptrdiff_t " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Id " , " ptrdiff_t " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-10-12 17:18:38 +02:00
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %I64u " , " unsigned __int64 " , " bool " ) ;
TEST_SCANF_WARN ( " %I64u " , " unsigned __int64 " , " char " ) ;
TEST_SCANF_WARN ( " %I64u " , " unsigned __int64 " , " signed char " ) ;
TEST_SCANF_WARN ( " %I64u " , " unsigned __int64 " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %I64u " , " unsigned __int64 " , " signed short " ) ;
TEST_SCANF_WARN ( " %I64u " , " unsigned __int64 " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %I64u " , " unsigned __int64 " , " signed int " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN ( " %I64u " , " unsigned __int64 " , " unsigned int " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %I64u " , " unsigned __int64 " , " signed long " ) ;
TEST_SCANF_WARN ( " %I64u " , " unsigned __int64 " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %I64u " , " unsigned __int64 " , " signed long long " ) ;
TEST_SCANF_NOWARN ( " %I64u " , " unsigned __int64 " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %I64u " , " unsigned __int64 " , " float " ) ;
TEST_SCANF_WARN ( " %I64u " , " unsigned __int64 " , " double " ) ;
TEST_SCANF_WARN ( " %I64u " , " unsigned __int64 " , " long double " ) ;
2017-11-07 21:43:30 +01:00
TEST_SCANF_WARN ( " %I64u " , " unsigned __int64 " , " void * " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN_AKA_WIN32 ( " %I64u " , " unsigned __int64 " , " size_t " , " unsigned long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %I64u " , " unsigned __int64 " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %I64u " , " unsigned __int64 " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
2017-11-06 20:04:59 +01:00
TEST_SCANF_WARN_AKA_WIN32 ( " %I64u " , " unsigned __int64 " , " unsigned ptrdiff_t " , " unsigned long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %I64u " , " unsigned __int64 " , " intmax_t " , " signed long " , " signed long long " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN_AKA_WIN32 ( " %I64u " , " unsigned __int64 " , " uintmax_t " , " unsigned long " ) ;
2017-11-08 16:13:45 +01:00
TEST_SCANF_WARN_AKA ( " %I64u " , " unsigned __int64 " , " intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_WIN32 ( " %I64u " , " unsigned __int64 " , " uintptr_t " , " unsigned long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP_WIN32 ( " %I64u " , " unsigned __int64 " , " std::size_t " , " unsigned long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %I64u " , " unsigned __int64 " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %I64u " , " unsigned __int64 " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %I64u " , " unsigned __int64 " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP_WIN32 ( " %I64u " , " unsigned __int64 " , " std::uintmax_t " , " unsigned long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %I64u " , " unsigned __int64 " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP_WIN32 ( " %I64u " , " unsigned __int64 " , " std::uintptr_t " , " unsigned long " ) ;
2016-01-31 13:49:17 +01:00
2017-10-17 17:07:42 +02:00
TEST_SCANF_WARN ( " %I64x " , " unsigned __int64 " , " bool " ) ;
2017-11-07 22:05:21 +01:00
TEST_SCANF_WARN ( " %I64x " , " unsigned __int64 " , " char " ) ;
2017-10-17 17:07:42 +02:00
TEST_SCANF_WARN ( " %I64x " , " unsigned __int64 " , " signed char " ) ;
TEST_SCANF_WARN ( " %I64x " , " unsigned __int64 " , " unsigned char " ) ;
2017-11-07 22:05:21 +01:00
TEST_SCANF_WARN ( " %I64x " , " unsigned __int64 " , " signed short " ) ;
TEST_SCANF_WARN ( " %I64x " , " unsigned __int64 " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %I64x " , " unsigned __int64 " , " signed int " ) ;
TEST_SCANF_WARN ( " %I64x " , " unsigned __int64 " , " unsigned int " ) ;
TEST_SCANF_WARN ( " %I64x " , " unsigned __int64 " , " signed long " ) ;
TEST_SCANF_WARN ( " %I64x " , " unsigned __int64 " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %I64x " , " unsigned __int64 " , " signed long long " ) ;
TEST_SCANF_NOWARN ( " %I64x " , " unsigned __int64 " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %I64x " , " unsigned __int64 " , " float " ) ;
TEST_SCANF_WARN ( " %I64x " , " unsigned __int64 " , " double " ) ;
TEST_SCANF_WARN ( " %I64x " , " unsigned __int64 " , " long double " ) ;
2017-10-17 17:07:42 +02:00
TEST_SCANF_WARN ( " %I64x " , " unsigned __int64 " , " void * " ) ;
2017-11-13 19:47:56 +01:00
TEST_SCANF_WARN_AKA_WIN32 ( " %I64x " , " unsigned __int64 " , " size_t " , " unsigned long " ) ;
2017-10-25 20:22:17 +02:00
TEST_SCANF_WARN_AKA ( " %I64x " , " unsigned __int64 " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %I64x " , " unsigned __int64 " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
2017-10-17 17:07:42 +02:00
TEST_SCANF_NOWARN ( " %I64x " , " unsigned __int64 " , " unsigned __int64 " ) ;
2017-10-25 20:22:17 +02:00
// TODO TEST_SCANF_WARN("%I64x", "unsigned __int64", "__int64");
2017-11-07 22:05:21 +01:00
TEST_SCANF_WARN_AKA_WIN32 ( " %I64x " , " unsigned __int64 " , " unsigned ptrdiff_t " , " unsigned long " ) ;
TEST_SCANF_WARN_AKA ( " %I64x " , " unsigned __int64 " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_WIN32 ( " %I64x " , " unsigned __int64 " , " uintmax_t " , " unsigned long " ) ;
2017-11-08 16:13:45 +01:00
TEST_SCANF_WARN_AKA ( " %I64x " , " unsigned __int64 " , " intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_WIN32 ( " %I64x " , " unsigned __int64 " , " uintptr_t " , " unsigned long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP_WIN32 ( " %I64x " , " unsigned __int64 " , " std::size_t " , " unsigned long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %I64x " , " unsigned __int64 " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %I64x " , " unsigned __int64 " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %I64x " , " unsigned __int64 " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP_WIN32 ( " %I64x " , " unsigned __int64 " , " std::uintmax_t " , " unsigned long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %I64x " , " unsigned __int64 " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP_WIN32 ( " %I64x " , " unsigned __int64 " , " std::uintptr_t " , " unsigned long " ) ;
2017-10-17 17:07:42 +02:00
2017-10-16 17:07:08 +02:00
TEST_SCANF_WARN ( " %I64d " , " __int64 " , " bool " ) ;
TEST_SCANF_WARN ( " %I64d " , " __int64 " , " signed char " ) ;
TEST_SCANF_WARN ( " %I64d " , " __int64 " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %I64d " , " __int64 " , " void * " ) ;
// TODO TEST_SCANF_WARN("%I64d", "__int64", "size_t");
2017-10-16 17:49:53 +02:00
TEST_SCANF_WARN_AKA_WIN32 ( " %I64d " , " __int64 " , " intmax_t " , " signed long " ) ;
TEST_SCANF_WARN_AKA_WIN32 ( " %I64d " , " __int64 " , " ssize_t " , " signed long " ) ;
TEST_SCANF_WARN_AKA_WIN32 ( " %I64d " , " __int64 " , " ptrdiff_t " , " signed long " ) ;
2017-10-16 17:07:08 +02:00
TEST_SCANF_NOWARN ( " %I64d " , " __int64 " , " __int64 " ) ;
2017-10-10 16:27:33 +02:00
TEST_SCANF_WARN ( " %I32u " , " unsigned __int32 " , " bool " ) ;
TEST_SCANF_WARN ( " %I32u " , " unsigned __int32 " , " char " ) ;
TEST_SCANF_WARN ( " %I32u " , " unsigned __int32 " , " signed char " ) ;
TEST_SCANF_WARN ( " %I32u " , " unsigned __int32 " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %I32u " , " unsigned __int32 " , " signed short " ) ;
TEST_SCANF_WARN ( " %I32u " , " unsigned __int32 " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %I32u " , " unsigned __int32 " , " signed int " ) ;
TEST_SCANF_NOWARN ( " %I32u " , " unsigned __int32 " , " unsigned int " ) ;
TEST_SCANF_WARN ( " %I32u " , " unsigned __int32 " , " signed long " ) ;
TEST_SCANF_WARN ( " %I32u " , " unsigned __int32 " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %I32u " , " unsigned __int32 " , " signed long long " ) ;
TEST_SCANF_WARN ( " %I32u " , " unsigned __int32 " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %I32u " , " unsigned __int32 " , " float " ) ;
TEST_SCANF_WARN ( " %I32u " , " unsigned __int32 " , " double " ) ;
TEST_SCANF_WARN ( " %I32u " , " unsigned __int32 " , " long double " ) ;
2017-11-07 21:43:30 +01:00
TEST_SCANF_WARN ( " %I32u " , " unsigned __int32 " , " void * " ) ;
2017-10-10 16:27:33 +02:00
TEST_SCANF_WARN_AKA ( " %I32u " , " unsigned __int32 " , " size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA ( " %I32u " , " unsigned __int32 " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %I32u " , " unsigned __int32 " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
2017-11-06 20:04:59 +01:00
TEST_SCANF_WARN_AKA ( " %I32u " , " unsigned __int32 " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
2017-10-10 16:27:33 +02:00
TEST_SCANF_WARN_AKA ( " %I32u " , " unsigned __int32 " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %I32u " , " unsigned __int32 " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-08 16:13:45 +01:00
TEST_SCANF_WARN_AKA ( " %I32u " , " unsigned __int32 " , " intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %I32u " , " unsigned __int32 " , " uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %I32u " , " unsigned __int32 " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %I32u " , " unsigned __int32 " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %I32u " , " unsigned __int32 " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %I32u " , " unsigned __int32 " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %I32u " , " unsigned __int32 " , " std::uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %I32u " , " unsigned __int32 " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %I32u " , " unsigned __int32 " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-10-10 16:27:33 +02:00
2017-10-12 17:18:38 +02:00
TEST_SCANF_WARN ( " %I32x " , " unsigned __int32 " , " bool " ) ;
TEST_SCANF_WARN ( " %I32x " , " unsigned __int32 " , " char " ) ;
TEST_SCANF_WARN ( " %I32x " , " unsigned __int32 " , " signed char " ) ;
TEST_SCANF_WARN ( " %I32x " , " unsigned __int32 " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %I32x " , " unsigned __int32 " , " signed short " ) ;
TEST_SCANF_WARN ( " %I32x " , " unsigned __int32 " , " unsigned short " ) ;
2017-10-25 20:22:17 +02:00
TEST_SCANF_WARN ( " %I32x " , " unsigned __int32 " , " signed int " ) ;
2017-10-12 17:18:38 +02:00
TEST_SCANF_NOWARN ( " %I32x " , " unsigned __int32 " , " unsigned int " ) ;
TEST_SCANF_WARN ( " %I32x " , " unsigned __int32 " , " signed long " ) ;
TEST_SCANF_WARN ( " %I32x " , " unsigned __int32 " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %I32x " , " unsigned __int32 " , " signed long long " ) ;
TEST_SCANF_WARN ( " %I32x " , " unsigned __int32 " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %I32x " , " unsigned __int32 " , " float " ) ;
TEST_SCANF_WARN ( " %I32x " , " unsigned __int32 " , " double " ) ;
TEST_SCANF_WARN ( " %I32x " , " unsigned __int32 " , " long double " ) ;
2017-11-07 21:43:30 +01:00
TEST_SCANF_WARN ( " %I32x " , " unsigned __int32 " , " void * " ) ;
2017-10-12 17:18:38 +02:00
TEST_SCANF_WARN_AKA ( " %I32x " , " unsigned __int32 " , " size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA ( " %I32x " , " unsigned __int32 " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %I32x " , " unsigned __int32 " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
2017-11-06 20:04:59 +01:00
TEST_SCANF_WARN_AKA ( " %I32x " , " unsigned __int32 " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
2017-10-12 17:18:38 +02:00
TEST_SCANF_WARN_AKA ( " %I32x " , " unsigned __int32 " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %I32x " , " unsigned __int32 " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-08 16:13:45 +01:00
TEST_SCANF_WARN_AKA ( " %I32x " , " unsigned __int32 " , " intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %I32x " , " unsigned __int32 " , " uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %I32x " , " unsigned __int32 " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %I32x " , " unsigned __int32 " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %I32x " , " unsigned __int32 " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %I32x " , " unsigned __int32 " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %I32x " , " unsigned __int32 " , " std::uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %I32x " , " unsigned __int32 " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %I32x " , " unsigned __int32 " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-10-12 17:18:38 +02:00
2017-10-16 17:07:08 +02:00
TEST_SCANF_WARN ( " %I32d " , " __int32 " , " bool " ) ;
TEST_SCANF_WARN ( " %I32d " , " __int32 " , " void * " ) ;
2019-11-19 16:05:21 +01:00
TEST_SCANF_WARN_AKA ( " %I32d " , " __int32 " , " size_t " , " unsigned long " , " unsigned long long " ) ;
2017-10-16 17:07:08 +02:00
//TODO TEST_SCANF_WARN_AKA_WIN32("%I32d", "__int32", "ssize_t", "signed long", "signed long long");
TEST_SCANF_WARN_AKA ( " %I32d " , " __int32 " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_NOWARN ( " %I32d " , " __int32 " , " __int32 " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %d " , " int " , " bool " ) ;
TEST_SCANF_WARN ( " %d " , " int " , " char " ) ;
TEST_SCANF_WARN ( " %d " , " int " , " signed char " ) ;
TEST_SCANF_WARN ( " %d " , " int " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %d " , " int " , " signed short " ) ;
TEST_SCANF_WARN ( " %d " , " int " , " unsigned short " ) ;
TEST_SCANF_NOWARN ( " %d " , " int " , " signed int " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN ( " %d " , " int " , " unsigned int " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %d " , " int " , " signed long " ) ;
TEST_SCANF_WARN ( " %d " , " int " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %d " , " int " , " signed long long " ) ;
TEST_SCANF_WARN ( " %d " , " int " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %d " , " int " , " float " ) ;
TEST_SCANF_WARN ( " %d " , " int " , " double " ) ;
TEST_SCANF_WARN ( " %d " , " int " , " long double " ) ;
TEST_SCANF_WARN ( " %d " , " int " , " void * " ) ;
TEST_SCANF_WARN_AKA ( " %d " , " int " , " size_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %d " , " int " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %d " , " int " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
2017-11-06 20:04:59 +01:00
TEST_SCANF_WARN_AKA ( " %d " , " int " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %d " , " int " , " intmax_t " , " signed long " , " signed long long " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN_AKA ( " %d " , " int " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %d " , " int " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %d " , " int " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %d " , " int " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %d " , " int " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %d " , " int " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 13:49:17 +01:00
2017-10-09 17:50:24 +02:00
check ( " void foo() { \n "
" scanf( \" %d \" , \" s3 \" ); \n "
" scanf( \" %d \" , L \" s5W \" ); \n "
" } " , true ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %d in format string (no. 1) requires 'int *' but the argument type is 'const char *'. \n "
" [test.cpp:3]: (warning) %d in format string (no. 1) requires 'int *' but the argument type is 'const wchar_t *'. \n " , errout . str ( ) ) ;
2017-10-23 22:35:32 +02:00
check ( " void foo(long l) { \n "
" scanf( \" %d \" , l); \n "
" } " , true ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %d in format string (no. 1) requires 'int *' but the argument type is 'signed long'. \n " , errout . str ( ) ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %x " , " unsigned int " , " bool " ) ;
TEST_SCANF_WARN ( " %x " , " unsigned int " , " char " ) ;
TEST_SCANF_WARN ( " %x " , " unsigned int " , " signed char " ) ;
TEST_SCANF_WARN ( " %x " , " unsigned int " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %x " , " unsigned int " , " signed short " ) ;
TEST_SCANF_WARN ( " %x " , " unsigned int " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %x " , " unsigned int " , " signed int " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_NOWARN ( " %x " , " unsigned int " , " unsigned int " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %x " , " unsigned int " , " signed long " ) ;
TEST_SCANF_WARN ( " %x " , " unsigned int " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %x " , " unsigned int " , " signed long long " ) ;
TEST_SCANF_WARN ( " %x " , " unsigned int " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %x " , " unsigned int " , " float " ) ;
TEST_SCANF_WARN ( " %x " , " unsigned int " , " double " ) ;
TEST_SCANF_WARN ( " %x " , " unsigned int " , " long double " ) ;
TEST_SCANF_WARN ( " %x " , " unsigned int " , " void * " ) ;
TEST_SCANF_WARN_AKA ( " %x " , " unsigned int " , " size_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %x " , " unsigned int " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %x " , " unsigned int " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
2017-11-06 20:04:59 +01:00
TEST_SCANF_WARN_AKA ( " %x " , " unsigned int " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %x " , " unsigned int " , " intmax_t " , " signed long " , " signed long long " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN_AKA ( " %x " , " unsigned int " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-08 16:13:45 +01:00
TEST_SCANF_WARN_AKA ( " %x " , " unsigned int " , " intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %x " , " unsigned int " , " uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %x " , " unsigned int " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %x " , " unsigned int " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %x " , " unsigned int " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %x " , " unsigned int " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %x " , " unsigned int " , " std::uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %x " , " unsigned int " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %x " , " unsigned int " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 13:49:17 +01:00
2017-10-09 17:50:24 +02:00
check ( " void foo() { \n "
" scanf( \" %x \" , \" s3 \" ); \n "
" scanf( \" %x \" , L \" s5W \" ); \n "
" } " , true ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'const char *'. \n "
" [test.cpp:3]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'const wchar_t *'. \n " , errout . str ( ) ) ;
2017-10-23 22:35:32 +02:00
check ( " void foo(long l) { \n "
" scanf( \" %x \" , l); \n "
" } " , true ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'signed long'. \n " , errout . str ( ) ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %f " , " float " , " bool " ) ;
TEST_SCANF_WARN ( " %f " , " float " , " char " ) ;
TEST_SCANF_WARN ( " %f " , " float " , " signed char " ) ;
TEST_SCANF_WARN ( " %f " , " float " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %f " , " float " , " signed short " ) ;
TEST_SCANF_WARN ( " %f " , " float " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %f " , " float " , " signed int " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN ( " %f " , " float " , " unsigned int " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %f " , " float " , " signed long " ) ;
TEST_SCANF_WARN ( " %f " , " float " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %f " , " float " , " signed long long " ) ;
TEST_SCANF_WARN ( " %f " , " float " , " unsigned long long " ) ;
TEST_SCANF_NOWARN ( " %f " , " float " , " float " ) ;
TEST_SCANF_WARN ( " %f " , " float " , " double " ) ;
TEST_SCANF_WARN ( " %f " , " float " , " long double " ) ;
TEST_SCANF_WARN ( " %f " , " float " , " void * " ) ;
TEST_SCANF_WARN_AKA ( " %f " , " float " , " size_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %f " , " float " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %f " , " float " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
2017-11-06 20:04:59 +01:00
TEST_SCANF_WARN_AKA ( " %f " , " float " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %f " , " float " , " intmax_t " , " signed long " , " signed long long " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN_AKA ( " %f " , " float " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %f " , " float " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %f " , " float " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %f " , " float " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %f " , " float " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %f " , " float " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 13:49:17 +01:00
2017-10-09 17:50:24 +02:00
check ( " void foo() { \n "
" scanf( \" %f \" , \" s3 \" ); \n "
" scanf( \" %f \" , L \" s5W \" ); \n "
" } " , true ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %f in format string (no. 1) requires 'float *' but the argument type is 'const char *'. \n "
" [test.cpp:3]: (warning) %f in format string (no. 1) requires 'float *' but the argument type is 'const wchar_t *'. \n " , errout . str ( ) ) ;
2017-10-23 22:35:32 +02:00
check ( " void foo(float f) { \n "
" scanf( \" %f \" , f); \n "
" } " , true ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %f in format string (no. 1) requires 'float *' but the argument type is 'float'. \n " , errout . str ( ) ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %lf " , " double " , " bool " ) ;
TEST_SCANF_WARN ( " %lf " , " double " , " char " ) ;
TEST_SCANF_WARN ( " %lf " , " double " , " signed char " ) ;
TEST_SCANF_WARN ( " %lf " , " double " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %lf " , " double " , " signed short " ) ;
TEST_SCANF_WARN ( " %lf " , " double " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %lf " , " double " , " signed int " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN ( " %lf " , " double " , " unsigned int " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %lf " , " double " , " signed long " ) ;
TEST_SCANF_WARN ( " %lf " , " double " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %lf " , " double " , " signed long long " ) ;
TEST_SCANF_WARN ( " %lf " , " double " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %lf " , " double " , " float " ) ;
TEST_SCANF_NOWARN ( " %lf " , " double " , " double " ) ;
TEST_SCANF_WARN ( " %lf " , " double " , " long double " ) ;
TEST_SCANF_WARN ( " %lf " , " double " , " void * " ) ;
TEST_SCANF_WARN_AKA ( " %lf " , " double " , " size_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %lf " , " double " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %lf " , " double " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
2017-11-06 20:04:59 +01:00
TEST_SCANF_WARN_AKA ( " %lf " , " double " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %lf " , " double " , " intmax_t " , " signed long " , " signed long long " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN_AKA ( " %lf " , " double " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %lf " , " double " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %lf " , " double " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %lf " , " double " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %lf " , " double " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %lf " , " double " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %Lf " , " long double " , " bool " ) ;
TEST_SCANF_WARN ( " %Lf " , " long double " , " char " ) ;
TEST_SCANF_WARN ( " %Lf " , " long double " , " signed char " ) ;
TEST_SCANF_WARN ( " %Lf " , " long double " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %Lf " , " long double " , " signed short " ) ;
TEST_SCANF_WARN ( " %Lf " , " long double " , " unsigned short " ) ;
TEST_SCANF_WARN ( " %Lf " , " long double " , " signed int " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN ( " %Lf " , " long double " , " unsigned int " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %Lf " , " long double " , " signed long " ) ;
TEST_SCANF_WARN ( " %Lf " , " long double " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %Lf " , " long double " , " signed long long " ) ;
TEST_SCANF_WARN ( " %Lf " , " long double " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %Lf " , " long double " , " float " ) ;
TEST_SCANF_WARN ( " %Lf " , " long double " , " double " ) ;
TEST_SCANF_NOWARN ( " %Lf " , " long double " , " long double " ) ;
TEST_SCANF_WARN ( " %Lf " , " long double " , " void * " ) ;
TEST_SCANF_WARN_AKA ( " %Lf " , " long double " , " size_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %Lf " , " long double " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %Lf " , " long double " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
2017-11-06 20:04:59 +01:00
TEST_SCANF_WARN_AKA ( " %Lf " , " long double " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %Lf " , " long double " , " intmax_t " , " signed long " , " signed long long " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN_AKA ( " %Lf " , " long double " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %Lf " , " long double " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Lf " , " long double " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Lf " , " long double " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Lf " , " long double " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %Lf " , " long double " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %n " , " int " , " bool " ) ;
TEST_SCANF_WARN ( " %n " , " int " , " char " ) ;
TEST_SCANF_WARN ( " %n " , " int " , " signed char " ) ;
TEST_SCANF_WARN ( " %n " , " int " , " unsigned char " ) ;
TEST_SCANF_WARN ( " %n " , " int " , " signed short " ) ;
TEST_SCANF_WARN ( " %n " , " int " , " unsigned short " ) ;
TEST_SCANF_NOWARN ( " %n " , " int " , " signed int " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN ( " %n " , " int " , " unsigned int " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN ( " %n " , " int " , " signed long " ) ;
TEST_SCANF_WARN ( " %n " , " int " , " unsigned long " ) ;
TEST_SCANF_WARN ( " %n " , " int " , " signed long long " ) ;
TEST_SCANF_WARN ( " %n " , " int " , " unsigned long long " ) ;
TEST_SCANF_WARN ( " %n " , " int " , " float " ) ;
TEST_SCANF_WARN ( " %n " , " int " , " double " ) ;
TEST_SCANF_WARN ( " %n " , " int " , " long double " ) ;
TEST_SCANF_WARN ( " %n " , " int " , " void * " ) ;
TEST_SCANF_WARN_AKA ( " %n " , " int " , " size_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %n " , " int " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA ( " %n " , " int " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
2017-11-06 20:04:59 +01:00
TEST_SCANF_WARN_AKA ( " %n " , " int " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
2016-01-31 14:34:26 +01:00
TEST_SCANF_WARN_AKA ( " %n " , " int " , " intmax_t " , " signed long " , " signed long long " ) ;
2016-01-31 13:49:17 +01:00
TEST_SCANF_WARN_AKA ( " %n " , " int " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_SCANF_WARN_AKA_CPP ( " %n " , " int " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %n " , " int " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %n " , " int " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %n " , " int " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_SCANF_WARN_AKA_CPP ( " %n " , " int " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2013-09-22 06:56:31 +02:00
2017-10-09 17:50:24 +02:00
check ( " void foo() { \n "
" scanf( \" %n \" , \" s3 \" ); \n "
" scanf( \" %n \" , L \" s5W \" ); \n "
" } " , true ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %n in format string (no. 1) requires 'int *' but the argument type is 'const char *'. \n "
" [test.cpp:3]: (warning) %n in format string (no. 1) requires 'int *' but the argument type is 'const wchar_t *'. \n " , errout . str ( ) ) ;
2017-10-23 22:35:32 +02:00
check ( " void foo(long l) { \n "
" scanf( \" %n \" , l); \n "
" } " , true ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %n in format string (no. 1) requires 'int *' but the argument type is 'signed long'. \n " , errout . str ( ) ) ;
2013-10-27 10:48:49 +01:00
check ( " void g() { \n " // #5104
" myvector<int> v1(1); \n "
2017-05-18 17:23:26 +02:00
" scanf( \" %d \" ,&v1[0]); \n "
2013-10-27 10:48:49 +01:00
" myvector<unsigned int> v2(1); \n "
2017-05-18 17:23:26 +02:00
" scanf( \" %u \" ,&v2[0]); \n "
2013-10-27 10:48:49 +01:00
" myvector<unsigned int> v3(1); \n "
2017-05-18 17:23:26 +02:00
" scanf( \" %x \" ,&v3[0]); \n "
2013-10-27 10:48:49 +01:00
" myvector<double> v4(1); \n "
2017-05-18 17:23:26 +02:00
" scanf( \" %lf \" ,&v4[0]); \n "
2013-10-27 10:48:49 +01:00
" myvector<char *> v5(1); \n "
2017-05-18 17:23:26 +02:00
" scanf( \" %10s \" ,v5[0]); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2013-10-27 10:48:49 +01:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2014-03-18 06:12:09 +01:00
{
const char * code = " void g() { \n " // #5348
" size_t s1; \n "
" ptrdiff_t s2; \n "
" ssize_t s3; \n "
" scanf( \" %zd \" , &s1); \n "
" scanf( \" %zd \" , &s2); \n "
" scanf( \" %zd \" , &s3); \n "
" } \n " ;
2017-11-08 12:22:03 +01:00
const char * result ( " [test.cpp:5]: (portability) % zd in format string ( no . 1 ) requires ' ssize_t * ' but the argument type is ' size_t * { aka unsigned long * } ' . \ n "
" [test.cpp:6]: (portability) %zd in format string (no. 1) requires 'ssize_t *' but the argument type is 'ptrdiff_t * {aka signed long *}'. \n " ) ;
const char * result_win64 ( " [test.cpp:5]: (portability) % zd in format string ( no . 1 ) requires ' ssize_t * ' but the argument type is ' size_t * { aka unsigned long long * } ' . \ n "
" [test.cpp:6]: (portability) %zd in format string (no. 1) requires 'ssize_t *' but the argument type is 'ptrdiff_t * {aka signed long long *}'. \n " ) ;
2014-03-18 06:12:09 +01:00
2023-03-03 18:36:27 +01:00
check ( code , false , true , cppcheck : : Platform : : Type : : Unix32 ) ;
2014-03-18 06:12:09 +01:00
ASSERT_EQUALS ( result , errout . str ( ) ) ;
2023-03-03 18:36:27 +01:00
check ( code , false , true , cppcheck : : Platform : : Type : : Unix64 ) ;
2014-03-18 06:12:09 +01:00
ASSERT_EQUALS ( result , errout . str ( ) ) ;
2023-03-03 18:36:27 +01:00
check ( code , false , true , cppcheck : : Platform : : Type : : Win32A ) ;
2014-03-18 06:12:09 +01:00
ASSERT_EQUALS ( result , errout . str ( ) ) ;
2023-03-03 18:36:27 +01:00
check ( code , false , true , cppcheck : : Platform : : Type : : Win64 ) ;
2014-03-18 06:12:09 +01:00
ASSERT_EQUALS ( result_win64 , errout . str ( ) ) ;
}
2014-04-18 11:39:58 +02:00
{
check ( " void g() { \n "
" const char c[]= \" 42 \" ; \n "
2017-05-18 17:23:26 +02:00
" scanf( \" %s \" , c); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2014-04-18 11:39:58 +02:00
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %s in format string (no. 1) requires a 'char *' but the argument type is 'const char *'. \n "
2016-05-26 21:10:50 +02:00
" [test.cpp:3]: (warning) scanf() without field width limits can crash with huge input data. \n " , errout . str ( ) ) ;
2014-04-18 11:39:58 +02:00
}
2021-12-20 17:22:39 +01:00
check ( " void f() { \n " // #7038
" scanf( \" %i \" , \" abc \" + 1); \n "
" } \n " ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %i in format string (no. 1) requires 'int *' but the argument type is 'const char *'. \n " , errout . str ( ) ) ;
2012-05-20 21:26:48 +02:00
}
2014-11-20 14:20:09 +01:00
void testPrintfArgument ( ) {
2012-05-20 21:26:48 +02:00
check ( " void foo() { \n "
2015-10-07 19:08:26 +02:00
" printf( \" %i \" ); \n "
" printf( \" %i%s \" , 123); \n "
" printf( \" %i%s%d \" , 0, bar()); \n "
" printf( \" %i%%%s%d \" , 0, bar()); \n "
" printf( \" %idfd%%dfa%s%d \" , 0, bar()); \n "
2012-05-20 21:26:48 +02:00
" fprintf(stderr, \" %u%s \" ); \n "
" snprintf(str,10, \" %u%s \" ); \n "
" sprintf(string1, \" %-*.*s \" , 32, string2); \n " // #3364
" snprintf(a, 9, \" %s%d \" , \" 11223344 \" ); \n " // #3655
" } " ) ;
2013-09-30 19:55:21 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (error) printf format string requires 1 parameter but only 0 are given. \n "
" [test.cpp:3]: (error) printf format string requires 2 parameters but only 1 is given. \n "
" [test.cpp:4]: (error) printf format string requires 3 parameters but only 2 are given. \n "
" [test.cpp:5]: (error) printf format string requires 3 parameters but only 2 are given. \n "
" [test.cpp:6]: (error) printf format string requires 3 parameters but only 2 are given. \n "
" [test.cpp:7]: (error) fprintf format string requires 2 parameters but only 0 are given. \n "
" [test.cpp:8]: (error) snprintf format string requires 2 parameters but only 0 are given. \n "
" [test.cpp:9]: (error) sprintf format string requires 3 parameters but only 2 are given. \n "
" [test.cpp:10]: (error) snprintf format string requires 2 parameters but only 1 is given. \n " , errout . str ( ) ) ;
2012-05-20 21:26:48 +02:00
check ( " void foo(char *str) { \n "
" printf( \" \" , 0); \n "
2015-10-07 19:08:26 +02:00
" printf( \" %i \" , 123, bar()); \n "
" printf( \" %i%s \" , 0, bar(), 43123); \n "
2012-05-20 21:26:48 +02:00
" } " ) ;
2013-09-30 19:55:21 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) printf format string requires 0 parameters but 1 is given. \n "
" [test.cpp:3]: (warning) printf format string requires 1 parameter but 2 are given. \n "
" [test.cpp:4]: (warning) printf format string requires 2 parameters but 3 are given. \n " , errout . str ( ) ) ;
2012-05-20 21:26:48 +02:00
2013-05-14 11:06:16 +02:00
check ( " void foo() { \n " // swprintf exists as MSVC extension and as standard function: #4790
2015-10-07 19:08:26 +02:00
" swprintf(string1, L \" %i \" , 32, string2); \n " // MSVC implementation
2013-05-14 11:06:16 +02:00
" swprintf(string1, L \" %s%s \" , L \" a \" , string2); \n " // MSVC implementation
2015-10-07 19:08:26 +02:00
" swprintf(string1, 6, L \" %i \" , 32, string2); \n " // Standard implementation
" swprintf(string1, 6, L \" %i%s \" , 32, string2); \n " // Standard implementation
2013-05-14 11:06:16 +02:00
" } " ) ;
2013-09-30 19:55:21 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) swprintf format string requires 1 parameter but 2 are given. \n "
" [test.cpp:4]: (warning) swprintf format string requires 1 parameter but 2 are given. \n " , errout . str ( ) ) ;
2013-05-14 11:06:16 +02:00
2012-05-20 21:26:48 +02:00
check ( " void foo(char *str) { \n "
2015-10-07 19:08:26 +02:00
" printf( \" %i \" , 0); \n "
" printf( \" %i%s \" , 123, bar()); \n "
" printf( \" %i%s%d \" , 0, bar(), 43123); \n "
" printf( \" %i%%%s%d \" , 0, bar(), 43123); \n "
" printf( \" %idfd%%dfa%s%d \" , 0, bar(), 43123); \n "
2017-05-18 17:23:26 +02:00
" printf( \" % \" PRId64 \" \" , 123); \n "
" fprintf(stderr, \" % \" PRId64 \" \" , 123); \n "
" snprintf(str,10, \" % \" PRId64 \" \" , 123); \n "
" fprintf(stderr, \" error: %m \" ); \n " // #3339
" printf( \" string: %.*s \" , len, string); \n " // #3311
" fprintf(stderr, \" %*cText. \" , indent, ' '); \n " // #3313
2012-05-20 21:26:48 +02:00
" sprintf(string1, \" %* \" , 32); \n " // #3364
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo(char* s, const char* s2, std::string s3, int i) { \n "
" printf( \" %s%s \" , s, s2); \n "
" printf( \" %s \" , i); \n "
" printf( \" %i%s \" , i, i); \n "
" printf( \" %s \" , s3); \n "
" printf( \" %s \" , \" s4 \" ); \n "
" printf( \" %u \" , s); \n "
" } " ) ;
2017-03-01 22:33:31 +01:00
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %s in format string (no. 1) requires 'char *' but the argument type is 'signed int'. \n "
" [test.cpp:4]: (warning) %s in format string (no. 2) requires 'char *' but the argument type is 'signed int'. \n "
2013-10-27 10:48:49 +01:00
" [test.cpp:5]: (warning) %s in format string (no. 1) requires 'char *' but the argument type is 'std::string'. \n "
2013-09-29 10:42:47 +02:00
" [test.cpp:7]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'char *'. \n " , errout . str ( ) ) ;
2012-05-20 21:26:48 +02:00
2017-10-04 16:51:35 +02:00
check ( " void foo(char* s, const char* s2, std::string s3, int i) { \n "
" printf( \" %jd \" , s); \n "
" printf( \" %ji \" , s); \n "
" printf( \" %ju \" , s2); \n "
" printf( \" %jo \" , s3); \n "
" printf( \" %jx \" , i); \n "
" printf( \" %jX \" , i); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %jd in format string (no. 1) requires 'intmax_t' but the argument type is 'char *'. \n "
" [test.cpp:3]: (warning) %ji in format string (no. 1) requires 'intmax_t' but the argument type is 'char *'. \n "
" [test.cpp:4]: (warning) %ju in format string (no. 1) requires 'uintmax_t' but the argument type is 'const char *'. \n "
" [test.cpp:5]: (warning) %jo in format string (no. 1) requires 'uintmax_t' but the argument type is 'std::string'. \n "
" [test.cpp:6]: (warning) %jx in format string (no. 1) requires 'uintmax_t' but the argument type is 'signed int'. \n "
" [test.cpp:7]: (warning) %jX in format string (no. 1) requires 'uintmax_t' but the argument type is 'signed int'. \n " , errout . str ( ) ) ;
2017-10-18 17:22:51 +02:00
check ( " void foo(uintmax_t uim, std::string s3, unsigned int ui, int i) { \n "
" printf( \" %ju \" , uim); \n "
" printf( \" %ju \" , ui); \n "
" printf( \" %jd \" , ui); \n "
" printf( \" %jd \" , s3); \n "
" printf( \" %jd \" , i); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %ju in format string (no. 1) requires 'uintmax_t' but the argument type is 'unsigned int'. \n "
" [test.cpp:4]: (warning) %jd in format string (no. 1) requires 'intmax_t' but the argument type is 'unsigned int'. \n "
" [test.cpp:5]: (warning) %jd in format string (no. 1) requires 'intmax_t' but the argument type is 'std::string'. \n "
" [test.cpp:6]: (warning) %jd in format string (no. 1) requires 'intmax_t' but the argument type is 'signed int'. \n " , errout . str ( ) ) ;
2012-05-20 21:26:48 +02:00
check ( " void foo(const int* cpi, const int ci, int i, int* pi, std::string s) { \n "
" printf( \" %n \" , cpi); \n "
" printf( \" %n \" , ci); \n "
" printf( \" %n \" , i); \n "
" printf( \" %n \" , pi); \n "
" printf( \" %n \" , s); \n "
" printf( \" %n \" , \" s4 \" ); \n "
" } " ) ;
2017-03-01 22:33:31 +01:00
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %n in format string (no. 1) requires 'int *' but the argument type is 'signed int'. \n "
" [test.cpp:4]: (warning) %n in format string (no. 1) requires 'int *' but the argument type is 'signed int'. \n "
2013-10-27 10:48:49 +01:00
" [test.cpp:6]: (warning) %n in format string (no. 1) requires 'int *' but the argument type is 'std::string'. \n "
2013-09-22 06:56:31 +02:00
" [test.cpp:7]: (warning) %n in format string (no. 1) requires 'int *' but the argument type is 'const char *'. \n " , errout . str ( ) ) ;
2012-05-20 21:26:48 +02:00
2017-10-05 16:45:06 +02:00
check ( " void foo() { \n "
" printf( \" %n \" , L \" s5W \" ); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %n in format string (no. 1) requires 'int *' but the argument type is 'const wchar_t *'. \n " , errout . str ( ) ) ;
2012-05-20 21:26:48 +02:00
check ( " class foo {}; \n "
2012-07-11 19:46:35 +02:00
" void foo(const int* cpi, foo f, bar b, bar* bp, double d, int i, unsigned int u) { \n "
" printf( \" %X \" , f); \n "
2012-05-20 21:26:48 +02:00
" printf( \" %c \" , \" s4 \" ); \n "
" printf( \" %o \" , d); \n "
2012-07-11 19:46:35 +02:00
" printf( \" %x \" , cpi); \n "
" printf( \" %o \" , b); \n "
" printf( \" %X \" , bp); \n "
" printf( \" %X \" , u); \n "
" printf( \" %X \" , i); \n "
2012-05-20 21:26:48 +02:00
" } " ) ;
2013-09-29 10:42:47 +02:00
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %X in format string (no. 1) requires 'unsigned int' but the argument type is 'foo'. \n "
" [test.cpp:4]: (warning) %c in format string (no. 1) requires 'unsigned int' but the argument type is 'const char *'. \n "
" [test.cpp:5]: (warning) %o in format string (no. 1) requires 'unsigned int' but the argument type is 'double'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:6]: (warning) %x in format string (no. 1) requires 'unsigned int' but the argument type is 'const signed int *'. \n "
2013-09-29 10:42:47 +02:00
" [test.cpp:8]: (warning) %X in format string (no. 1) requires 'unsigned int' but the argument type is 'bar *'. \n " , errout . str ( ) ) ;
2012-05-20 21:26:48 +02:00
2017-10-19 18:03:12 +02:00
check ( " class foo {}; \n "
" void foo(const char* cpc, char* pc) { \n "
" printf( \" %x \" , cpc); \n "
" printf( \" %x \" , pc); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %x in format string (no. 1) requires 'unsigned int' but the argument type is 'const char *'. \n "
" [test.cpp:4]: (warning) %x in format string (no. 1) requires 'unsigned int' but the argument type is 'char *'. \n " , errout . str ( ) ) ;
2017-10-05 16:45:06 +02:00
check ( " class foo {}; \n "
" void foo() { \n "
" printf( \" %x \" , L \" s5W \" ); \n "
" printf( \" %X \" , L \" s5W \" ); \n "
" printf( \" %c \" , L \" s5W \" ); \n "
" printf( \" %o \" , L \" s5W \" ); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %x in format string (no. 1) requires 'unsigned int' but the argument type is 'const wchar_t *'. \n "
" [test.cpp:4]: (warning) %X in format string (no. 1) requires 'unsigned int' but the argument type is 'const wchar_t *'. \n "
" [test.cpp:5]: (warning) %c in format string (no. 1) requires 'unsigned int' but the argument type is 'const wchar_t *'. \n "
" [test.cpp:6]: (warning) %o in format string (no. 1) requires 'unsigned int' but the argument type is 'const wchar_t *'. \n " , errout . str ( ) ) ;
2012-07-11 19:46:35 +02:00
check ( " class foo {}; \n "
" void foo(const int* cpi, foo f, bar b, bar* bp, double d, unsigned int u, unsigned char uc) { \n "
" printf( \" %i \" , f); \n "
" printf( \" %d \" , \" s4 \" ); \n "
" printf( \" %d \" , d); \n "
" printf( \" %d \" , u); \n "
" printf( \" %d \" , cpi); \n "
" printf( \" %i \" , b); \n "
" printf( \" %i \" , bp); \n "
" printf( \" %i \" , uc); \n " // char is smaller than int, so there shouldn't be a problem
" } " ) ;
2013-09-29 10:42:47 +02:00
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %i in format string (no. 1) requires 'int' but the argument type is 'foo'. \n "
" [test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'const char *'. \n "
" [test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'double'. \n "
" [test.cpp:6]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:7]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'const signed int *'. \n "
2013-09-29 10:42:47 +02:00
" [test.cpp:9]: (warning) %i in format string (no. 1) requires 'int' but the argument type is 'bar *'. \n " , errout . str ( ) ) ;
2012-07-11 19:46:35 +02:00
2017-10-05 16:45:06 +02:00
check ( " class foo {}; \n "
" void foo() { \n "
" printf( \" %i \" , L \" s5W \" ); \n "
" printf( \" %d \" , L \" s5W \" ); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %i in format string (no. 1) requires 'int' but the argument type is 'const wchar_t *'. \n "
" [test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'const wchar_t *'. \n " , errout . str ( ) ) ;
2012-07-11 19:46:35 +02:00
check ( " class foo {}; \n "
" void foo(const int* cpi, foo f, bar b, bar* bp, double d, int i, bool bo) { \n "
" printf( \" %u \" , f); \n "
" printf( \" %u \" , \" s4 \" ); \n "
" printf( \" %u \" , d); \n "
" printf( \" %u \" , i); \n "
" printf( \" %u \" , cpi); \n "
" printf( \" %u \" , b); \n "
" printf( \" %u \" , bp); \n "
" printf( \" %u \" , bo); \n " // bool shouldn't have a negative sign
" } " ) ;
2013-09-29 10:42:47 +02:00
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'foo'. \n "
" [test.cpp:4]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'const char *'. \n "
" [test.cpp:5]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'double'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:6]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'. \n "
" [test.cpp:7]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'const signed int *'. \n "
2013-09-29 10:42:47 +02:00
" [test.cpp:9]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'bar *'. \n " , errout . str ( ) ) ;
2012-07-11 19:46:35 +02:00
2017-10-05 16:45:06 +02:00
check ( " class foo {}; \n "
" void foo(const int* cpi, foo f, bar b, bar* bp, double d, int i, bool bo) { \n "
" printf( \" %u \" , L \" s5W \" ); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'const wchar_t *'. \n " , errout . str ( ) ) ;
2012-05-20 21:26:48 +02:00
check ( " class foo {}; \n "
" void foo(const int* cpi, foo f, bar b, bar* bp, char c) { \n "
" printf( \" %p \" , f); \n "
" printf( \" %p \" , c); \n "
" printf( \" %p \" , bp); \n "
" printf( \" %p \" , cpi); \n "
" printf( \" %p \" , b); \n "
" } " ) ;
2013-08-31 06:26:39 +02:00
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 ( ) ) ;
2012-05-20 21:26:48 +02:00
2017-10-08 10:14:10 +02:00
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 ( ) ) ;
2012-05-20 21:26:48 +02:00
check ( " class foo {}; \n "
" void foo(const int* cpi, foo f, bar b, bar* bp, double d) { \n "
" printf( \" %e \" , f); \n "
" printf( \" %E \" , \" s4 \" ); \n "
" printf( \" %f \" , cpi); \n "
" printf( \" %G \" , bp); \n "
" printf( \" %f \" , d); \n "
" printf( \" %f \" , b); \n "
" printf( \" %f \" , (float)cpi); \n "
" } " ) ;
2013-09-29 10:42:47 +02:00
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %e in format string (no. 1) requires 'double' but the argument type is 'foo'. \n "
" [test.cpp:4]: (warning) %E in format string (no. 1) requires 'double' but the argument type is 'const char *'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:5]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'const signed int *'. \n "
2013-09-29 10:42:47 +02:00
" [test.cpp:6]: (warning) %G in format string (no. 1) requires 'double' but the argument type is 'bar *'. \n " , errout . str ( ) ) ;
2012-05-20 21:26:48 +02:00
2017-10-19 18:03:12 +02:00
check ( " class foo {}; \n "
" void foo(const char* cpc, char* pc) { \n "
" printf( \" %e \" , cpc); \n "
" printf( \" %E \" , pc); \n "
" printf( \" %f \" , cpc); \n "
" printf( \" %G \" , pc); \n "
" printf( \" %f \" , pc); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %e in format string (no. 1) requires 'double' but the argument type is 'const char *'. \n "
" [test.cpp:4]: (warning) %E in format string (no. 1) requires 'double' but the argument type is 'char *'. \n "
" [test.cpp:5]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'const char *'. \n "
" [test.cpp:6]: (warning) %G in format string (no. 1) requires 'double' but the argument type is 'char *'. \n "
" [test.cpp:7]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'char *'. \n " , errout . str ( ) ) ;
2017-10-05 16:45:06 +02:00
check ( " class foo {}; \n "
" void foo() { \n "
" printf( \" %e \" , L \" s5W \" ); \n "
" printf( \" %E \" , L \" s5W \" ); \n "
" printf( \" %f \" , L \" s5W \" ); \n "
" printf( \" %G \" , L \" s5W \" ); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %e in format string (no. 1) requires 'double' but the argument type is 'const wchar_t *'. \n "
" [test.cpp:4]: (warning) %E in format string (no. 1) requires 'double' but the argument type is 'const wchar_t *'. \n "
" [test.cpp:5]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'const wchar_t *'. \n "
" [test.cpp:6]: (warning) %G in format string (no. 1) requires 'double' but the argument type is 'const wchar_t *'. \n " , errout . str ( ) ) ;
2012-05-20 21:26:48 +02:00
check ( " class foo; \n "
" void foo(foo f) { \n "
" printf( \" %u \" , f); \n "
" printf( \" %f \" , f); \n "
" printf( \" %p \" , f); \n "
" } " ) ;
2013-09-29 10:42:47 +02:00
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'foo'. \n "
" [test.cpp:4]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'foo'. \n "
2013-08-31 06:26:39 +02:00
" [test.cpp:5]: (warning) %p in format string (no. 1) requires an address but the argument type is 'foo'. \n " , errout . str ( ) ) ;
2012-10-21 08:50:29 +02:00
// Ticket #4189 (Improve check (printf("%l") not detected)) tests (according to C99 7.19.6.1.7)
// False positive tests
check ( " void foo(signed char sc, unsigned char uc, short int si, unsigned short int usi) { \n "
" printf( \" %hhx %hhd \" , sc, uc); \n "
2013-07-22 08:28:29 +02:00
" printf( \" %hd %hu \" , si, usi); \n "
2012-10-21 08:50:29 +02:00
" } " ) ;
2017-11-21 20:14:48 +01:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %hhx in format string (no. 1) requires 'unsigned char' but the argument type is 'signed char'. \n "
" [test.cpp:2]: (warning) %hhd in format string (no. 2) requires 'char' but the argument type is 'unsigned char'. \n " , errout . str ( ) ) ;
2012-10-21 08:50:29 +02:00
check ( " void foo(long long int lli, unsigned long long int ulli, long int li, unsigned long int uli) { \n "
" printf( \" %llo %llx \" , lli, ulli); \n "
" printf( \" %ld %lu \" , li, uli); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2014-05-04 07:55:23 +02:00
check ( " void foo(intmax_t im, uintmax_t uim, size_t s, ptrdiff_t p, long double ld, std::size_t ss, std::ptrdiff_t sp) { \n "
2012-10-21 08:50:29 +02:00
" printf( \" %jd %jo \" , im, uim); \n "
" printf( \" %zx \" , s); \n "
" printf( \" %ti \" , p); \n "
2017-10-20 20:46:24 +02:00
" printf( \" %Lf \" , ld); \n "
2014-05-04 07:55:23 +02:00
" printf( \" %zx \" , ss); \n "
" printf( \" %ti \" , sp); \n "
2012-10-21 08:50:29 +02:00
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2017-10-20 20:46:24 +02:00
// Unrecognized (and non-existent in standard library) specifiers.
// Perhaps should emit warnings
check ( " void foo(intmax_t im, uintmax_t uim, size_t s, ptrdiff_t p, long double ld, std::size_t ss, std::ptrdiff_t sp) { \n "
" printf( \" %jb %jw \" , im, uim); \n "
" printf( \" %zr \" , s); \n "
" printf( \" %tm \" , p); \n "
" printf( \" %La \" , ld); \n "
" printf( \" %zv \" , ss); \n "
" printf( \" %tp \" , sp); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2017-10-18 18:00:40 +02:00
check ( " void foo(long long l, ptrdiff_t p, std::ptrdiff_t sp) { \n "
" printf( \" %td \" , p); \n "
" printf( \" %td \" , sp); \n "
" printf( \" %td \" , l); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:4]: (warning) %td in format string (no. 1) requires 'ptrdiff_t' but the argument type is 'signed long long'. \n " , errout . str ( ) ) ;
2017-10-13 17:17:33 +02:00
check ( " void foo(int i, long double ld) { \n "
" printf( \" %zx %zu \" , i, ld); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %zx in format string (no. 1) requires 'size_t' but the argument type is 'signed int'. \n "
" [test.cpp:2]: (warning) %zu in format string (no. 2) requires 'size_t' but the argument type is 'long double'. \n " , errout . str ( ) ) ;
2017-10-23 22:44:22 +02:00
check ( " void foo(unsigned int ui, long double ld) { \n "
" printf( \" %zu %zx \" , ui, ld); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %zu in format string (no. 1) requires 'size_t' but the argument type is 'unsigned int'. \n "
" [test.cpp:2]: (warning) %zx in format string (no. 2) requires 'size_t' but the argument type is 'long double'. \n " , errout . str ( ) ) ;
2017-10-19 18:05:16 +02:00
check ( " void foo(int i, long double ld) { \n "
" printf( \" %tx %tu \" , i, ld); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %tx in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'signed int'. \n "
" [test.cpp:2]: (warning) %tu in format string (no. 2) requires 'unsigned ptrdiff_t' but the argument type is 'long double'. \n " , errout . str ( ) ) ;
2012-10-21 08:50:29 +02:00
// False negative test
check ( " void foo(unsigned int i) { \n "
" printf( \" %h \" , i); \n "
" printf( \" %hh \" , i); \n "
" printf( \" %l \" , i); \n "
" printf( \" %ll \" , i); \n "
" printf( \" %j \" , i); \n "
" printf( \" %z \" , i); \n "
" printf( \" %t \" , i); \n "
" printf( \" %L \" , i); \n "
2017-10-16 16:51:38 +02:00
" printf( \" %I \" , i); \n "
2012-10-21 08:50:29 +02:00
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) 'h' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:3]: (warning) 'hh' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:4]: (warning) 'l' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:5]: (warning) 'll' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:6]: (warning) 'j' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:7]: (warning) 'z' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:8]: (warning) 't' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
2017-10-16 16:51:38 +02:00
" [test.cpp:9]: (warning) 'L' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:10]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n " , errout . str ( ) ) ;
2013-07-22 08:28:29 +02:00
check ( " void foo(unsigned int i) { \n "
" printf( \" %hd \" , i); \n "
" printf( \" %hhd \" , i); \n "
" printf( \" %ld \" , i); \n "
" printf( \" %lld \" , i); \n "
" } " ) ;
2016-08-24 12:47:11 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %hd in format string (no. 1) requires 'short' but the argument type is 'unsigned int'. \n "
" [test.cpp:3]: (warning) %hhd in format string (no. 1) requires 'char' but the argument type is 'unsigned int'. \n "
2013-09-29 10:42:47 +02:00
" [test.cpp:4]: (warning) %ld in format string (no. 1) requires 'long' but the argument type is 'unsigned int'. \n "
2018-01-08 20:20:33 +01:00
" [test.cpp:5]: (warning) %lld in format string (no. 1) requires 'long long' but the argument type is 'unsigned int'. \n " , errout . str ( ) ) ;
2013-07-22 08:28:29 +02:00
check ( " void foo(size_t s, ptrdiff_t p) { \n "
" printf( \" %zd \" , s); \n "
" printf( \" %tu \" , p); \n "
2023-03-03 18:36:27 +01:00
" } " , false , true , cppcheck : : Platform : : Type : : Unix32 ) ;
2016-09-11 17:05:01 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'size_t {aka unsigned long}'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'ptrdiff_t {aka signed long}'. \n " , errout . str ( ) ) ;
2013-08-31 06:26:39 +02:00
2014-05-04 07:55:23 +02:00
check ( " void foo(std::size_t s, std::ptrdiff_t p) { \n "
" printf( \" %zd \" , s); \n "
" printf( \" %tu \" , p); \n "
2023-03-03 18:36:27 +01:00
" } " , false , true , cppcheck : : Platform : : Type : : Unix32 ) ;
2016-09-11 17:05:01 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'std::size_t {aka unsigned long}'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'std::ptrdiff_t {aka signed long}'. \n " , errout . str ( ) ) ;
2014-05-04 07:55:23 +02:00
2013-08-31 06:26:39 +02:00
check ( " void foo(size_t s, ptrdiff_t p) { \n "
" printf( \" %zd \" , s); \n "
" printf( \" %tu \" , p); \n "
2023-03-03 18:36:27 +01:00
" } " , false , true , cppcheck : : Platform : : Type : : Unix64 ) ;
2016-09-11 17:05:01 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'size_t {aka unsigned long}'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'ptrdiff_t {aka signed long}'. \n " , errout . str ( ) ) ;
2013-08-31 06:26:39 +02:00
2014-05-04 07:55:23 +02:00
check ( " void foo(std::size_t s, std::ptrdiff_t p) { \n "
" printf( \" %zd \" , s); \n "
" printf( \" %tu \" , p); \n "
2023-03-03 18:36:27 +01:00
" } " , false , true , cppcheck : : Platform : : Type : : Unix64 ) ;
2016-09-11 17:05:01 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'std::size_t {aka unsigned long}'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'std::ptrdiff_t {aka signed long}'. \n " , errout . str ( ) ) ;
2014-05-04 07:55:23 +02:00
2013-08-31 06:26:39 +02:00
check ( " void foo(size_t s, ptrdiff_t p) { \n "
" printf( \" %zd \" , s); \n "
" printf( \" %tu \" , p); \n "
2023-03-03 18:36:27 +01:00
" } " , false , true , cppcheck : : Platform : : Type : : Win32A ) ;
2016-09-11 17:05:01 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'size_t {aka unsigned long}'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'ptrdiff_t {aka signed long}'. \n " , errout . str ( ) ) ;
2013-08-31 06:26:39 +02:00
2014-05-04 07:55:23 +02:00
check ( " void foo(std::size_t s, std::ptrdiff_t p) { \n "
" printf( \" %zd \" , s); \n "
" printf( \" %tu \" , p); \n "
2023-03-03 18:36:27 +01:00
" } " , false , true , cppcheck : : Platform : : Type : : Win32A ) ;
2016-09-11 17:05:01 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'std::size_t {aka unsigned long}'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'std::ptrdiff_t {aka signed long}'. \n " , errout . str ( ) ) ;
2014-05-04 07:55:23 +02:00
2013-08-31 06:26:39 +02:00
check ( " void foo(size_t s, ptrdiff_t p) { \n "
" printf( \" %zd \" , s); \n "
" printf( \" %tu \" , p); \n "
2023-03-03 18:36:27 +01:00
" } " , false , true , cppcheck : : Platform : : Type : : Win64 ) ;
2016-09-11 17:05:01 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'size_t {aka unsigned long long}'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'ptrdiff_t {aka signed long long}'. \n " , errout . str ( ) ) ;
2013-07-22 08:28:29 +02:00
2014-05-04 07:55:23 +02:00
check ( " void foo(std::size_t s, std::ptrdiff_t p) { \n "
" printf( \" %zd \" , s); \n "
" printf( \" %tu \" , p); \n "
2023-03-03 18:36:27 +01:00
" } " , false , true , cppcheck : : Platform : : Type : : Win64 ) ;
2016-09-11 17:05:01 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'std::size_t {aka unsigned long long}'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'std::ptrdiff_t {aka signed long long}'. \n " , errout . str ( ) ) ;
2014-05-04 07:55:23 +02:00
2017-11-07 19:44:46 +01:00
check ( " void foo(size_t s, uintmax_t um) { \n "
" printf( \" %lu \" , s); \n "
" printf( \" %lu \" , um); \n "
" printf( \" %llu \" , s); \n "
" printf( \" %llu \" , um); \n "
2023-03-03 18:36:27 +01:00
" } " , false , true , cppcheck : : Platform : : Type : : Win64 ) ;
2017-11-07 19:44:46 +01:00
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 "
" [test.cpp:3]: (portability) %lu in format string (no. 1) requires 'unsigned long' but the argument type is 'uintmax_t {aka unsigned long long}'. \n "
" [test.cpp:4]: (portability) %llu in format string (no. 1) requires 'unsigned long long' but the argument type is 'size_t {aka unsigned long long}'. \n "
" [test.cpp:5]: (portability) %llu in format string (no. 1) requires 'unsigned long long' but the argument type is 'uintmax_t {aka unsigned long long}'. \n " , errout . str ( ) ) ;
2013-08-10 12:33:55 +02:00
check ( " void foo(unsigned int i) { \n "
" printf( \" %ld \" , i); \n "
" printf( \" %lld \" , i); \n "
" printf( \" %lu \" , i); \n "
" printf( \" %llu \" , i); \n "
" printf( \" %lx \" , i); \n "
" printf( \" %llx \" , i); \n "
" } " ) ;
2013-09-29 10:42:47 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %ld in format string (no. 1) requires 'long' but the argument type is 'unsigned int'. \n "
" [test.cpp:3]: (warning) %lld in format string (no. 1) requires 'long long' but the argument type is 'unsigned int'. \n "
" [test.cpp:4]: (warning) %lu in format string (no. 1) requires 'unsigned long' but the argument type is 'unsigned int'. \n "
" [test.cpp:5]: (warning) %llu in format string (no. 1) requires 'unsigned long long' but the argument type is 'unsigned int'. \n "
" [test.cpp:6]: (warning) %lx in format string (no. 1) requires 'unsigned long' but the argument type is 'unsigned int'. \n "
" [test.cpp:7]: (warning) %llx in format string (no. 1) requires 'unsigned long long' but the argument type is 'unsigned int'. \n " , errout . str ( ) ) ;
2013-08-20 06:16:31 +02:00
2017-10-27 21:25:34 +02:00
check ( " void foo(int i, intmax_t im, ptrdiff_t p) { \n "
" printf( \" %lld \" , i); \n "
" printf( \" %lld \" , im); \n "
" printf( \" %lld \" , p); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %lld in format string (no. 1) requires 'long long' but the argument type is 'signed int'. \n " , errout . str ( ) ) ;
check ( " void foo(intmax_t im, ptrdiff_t p) { \n "
" printf( \" %lld \" , im); \n "
" printf( \" %lld \" , p); \n "
2023-03-03 18:36:27 +01:00
" } " , false , true , cppcheck : : Platform : : Type : : Win64 ) ;
2017-10-27 21:25:34 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (portability) %lld in format string (no. 1) requires 'long long' but the argument type is 'intmax_t {aka signed long long}'. \n "
" [test.cpp:3]: (portability) %lld in format string (no. 1) requires 'long long' but the argument type is 'ptrdiff_t {aka signed long long}'. \n " , errout . str ( ) ) ;
2013-08-20 06:16:31 +02:00
check ( " class Foo { \n "
" double d; \n "
2013-08-23 05:35:57 +02:00
" struct Bar { \n "
" int i; \n "
" } bar[2]; \n "
" struct Baz { \n "
" int i; \n "
" } baz; \n "
2013-08-20 06:16:31 +02:00
" }; \n "
" int a[10]; \n "
2013-08-23 05:35:57 +02:00
" Foo f[10]; \n "
2013-08-20 06:16:31 +02:00
" void foo(const Foo* foo) { \n "
2013-08-23 05:35:57 +02:00
" printf( \" %d %f %f %d %f %f \" , \n "
" foo->d, foo->bar[0].i, a[0], \n "
" f[0].d, f[0].baz.i, f[0].bar[0].i); \n "
" } " ) ;
2013-09-29 10:42:47 +02:00
ASSERT_EQUALS ( " [test.cpp:13]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'double'. \n "
2016-02-04 20:49:13 +01:00
" [test.cpp:13]: (warning) %f in format string (no. 2) requires 'double' but the argument type is 'signed int'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:13]: (warning) %f in format string (no. 3) requires 'double' but the argument type is 'int'. \n "
2013-09-29 10:42:47 +02:00
" [test.cpp:13]: (warning) %d in format string (no. 4) requires 'int' but the argument type is 'double'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:13]: (warning) %f in format string (no. 5) requires 'double' but the argument type is 'int'. \n "
" [test.cpp:13]: (warning) %f in format string (no. 6) requires 'double' but the argument type is 'int'. \n " , errout . str ( ) ) ;
2013-08-24 07:25:50 +02:00
check ( " short f() { return 0; } \n "
2013-09-12 05:54:05 +02:00
" void foo() { printf( \" %d %u %lu %I64u %I64d %f %Lf %p \" , f(), f(), f(), f(), f(), f(), f(), f()); } " ) ;
2016-08-14 17:19:14 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed short'. \n "
" [test.cpp:2]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed short'. \n "
" [test.cpp:2]: (warning) %I64u in format string (no. 4) requires 'unsigned __int64' but the argument type is 'signed short'. \n "
" [test.cpp:2]: (warning) %I64d in format string (no. 5) requires '__int64' but the argument type is 'signed short'. \n "
" [test.cpp:2]: (warning) %f in format string (no. 6) requires 'double' but the argument type is 'signed short'. \n "
" [test.cpp:2]: (warning) %Lf in format string (no. 7) requires 'long double' but the argument type is 'signed short'. \n "
" [test.cpp:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'signed short'. \n " , errout . str ( ) ) ;
2013-08-24 07:25:50 +02:00
check ( " unsigned short f() { return 0; } \n "
2013-09-12 05:54:05 +02:00
" void foo() { printf( \" %u %d %ld %I64d %I64u %f %Lf %p \" , f(), f(), f(), f(), f(), f(), f(), f()); } " ) ;
2013-09-29 10:42:47 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'unsigned short'. \n "
" [test.cpp:2]: (warning) %I64d in format string (no. 4) requires '__int64' but the argument type is 'unsigned short'. \n "
" [test.cpp:2]: (warning) %I64u in format string (no. 5) requires 'unsigned __int64' but the argument type is 'unsigned short'. \n "
" [test.cpp:2]: (warning) %f in format string (no. 6) requires 'double' but the argument type is 'unsigned short'. \n "
" [test.cpp:2]: (warning) %Lf in format string (no. 7) requires 'long double' but the argument type is 'unsigned short'. \n "
2013-08-31 06:26:39 +02:00
" [test.cpp:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'unsigned short'. \n " , errout . str ( ) ) ;
2013-08-24 07:25:50 +02:00
check ( " int f() { return 0; } \n "
2013-09-12 05:54:05 +02:00
" void foo() { printf( \" %d %u %lu %I64u %I64d %f %Lf %p \" , f(), f(), f(), f(), f(), f(), f(), f()); } " ) ;
2016-08-14 17:19:14 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
" [test.cpp:2]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'. \n "
" [test.cpp:2]: (warning) %I64u in format string (no. 4) requires 'unsigned __int64' but the argument type is 'signed int'. \n "
" [test.cpp:2]: (warning) %I64d in format string (no. 5) requires '__int64' but the argument type is 'signed int'. \n "
" [test.cpp:2]: (warning) %f in format string (no. 6) requires 'double' but the argument type is 'signed int'. \n "
" [test.cpp:2]: (warning) %Lf in format string (no. 7) requires 'long double' but the argument type is 'signed int'. \n "
" [test.cpp:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'signed int'. \n " , errout . str ( ) ) ;
2013-08-24 07:25:50 +02:00
check ( " unsigned int f() { return 0; } \n "
2013-09-12 05:54:05 +02:00
" void foo() { printf( \" %u %d %ld %I64d %I64u %f %Lf %p \" , f(), f(), f(), f(), f(), f(), f(), f()); } " ) ;
2013-09-29 10:42:47 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'. \n "
" [test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'unsigned int'. \n "
" [test.cpp:2]: (warning) %I64d in format string (no. 4) requires '__int64' but the argument type is 'unsigned int'. \n "
" [test.cpp:2]: (warning) %I64u in format string (no. 5) requires 'unsigned __int64' but the argument type is 'unsigned int'. \n "
" [test.cpp:2]: (warning) %f in format string (no. 6) requires 'double' but the argument type is 'unsigned int'. \n "
" [test.cpp:2]: (warning) %Lf in format string (no. 7) requires 'long double' but the argument type is 'unsigned int'. \n "
2013-08-31 06:26:39 +02:00
" [test.cpp:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'unsigned int'. \n " , errout . str ( ) ) ;
2013-08-26 06:03:26 +02:00
check ( " long f() { return 0; } \n "
2013-09-12 05:54:05 +02:00
" void foo() { printf( \" %ld %u %lu %I64u %I64d %f %Lf %p \" , f(), f(), f(), f(), f(), f(), f(), f()); } " ) ;
2016-08-14 17:19:14 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed long'. \n "
" [test.cpp:2]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed long'. \n "
" [test.cpp:2]: (warning) %I64u in format string (no. 4) requires 'unsigned __int64' but the argument type is 'signed long'. \n "
" [test.cpp:2]: (warning) %I64d in format string (no. 5) requires '__int64' but the argument type is 'signed long'. \n "
" [test.cpp:2]: (warning) %f in format string (no. 6) requires 'double' but the argument type is 'signed long'. \n "
" [test.cpp:2]: (warning) %Lf in format string (no. 7) requires 'long double' but the argument type is 'signed long'. \n "
" [test.cpp:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'signed long'. \n " , errout . str ( ) ) ;
2013-08-24 07:25:50 +02:00
check ( " unsigned long f() { return 0; } \n "
2013-09-12 05:54:05 +02:00
" void foo() { printf( \" %lu %d %ld %I64d %I64u %f %Lf %p \" , f(), f(), f(), f(), f(), f(), f(), f()); } " ) ;
2013-09-29 10:42:47 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned long'. \n "
" [test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'unsigned long'. \n "
" [test.cpp:2]: (warning) %I64d in format string (no. 4) requires '__int64' but the argument type is 'unsigned long'. \n "
" [test.cpp:2]: (warning) %I64u in format string (no. 5) requires 'unsigned __int64' but the argument type is 'unsigned long'. \n "
" [test.cpp:2]: (warning) %f in format string (no. 6) requires 'double' but the argument type is 'unsigned long'. \n "
" [test.cpp:2]: (warning) %Lf in format string (no. 7) requires 'long double' but the argument type is 'unsigned long'. \n "
2013-08-31 06:26:39 +02:00
" [test.cpp:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'unsigned long'. \n " , errout . str ( ) ) ;
2013-08-29 05:49:16 +02:00
check ( " long long f() { return 0; } \n "
2013-09-12 05:54:05 +02:00
" void foo() { printf( \" %lld %u %lu %I64u %I64d %f %Lf %p \" , f(), f(), f(), f(), f(), f(), f(), f()); } " ) ;
2016-08-14 17:19:14 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed long long'. \n "
" [test.cpp:2]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed long long'. \n "
" [test.cpp:2]: (warning) %I64u in format string (no. 4) requires 'unsigned __int64' but the argument type is 'signed long long'. \n "
" [test.cpp:2]: (warning) %f in format string (no. 6) requires 'double' but the argument type is 'signed long long'. \n "
" [test.cpp:2]: (warning) %Lf in format string (no. 7) requires 'long double' but the argument type is 'signed long long'. \n "
" [test.cpp:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'signed long long'. \n " , errout . str ( ) ) ;
2013-08-29 05:49:16 +02:00
check ( " unsigned long long f() { return 0; } \n "
2013-09-12 05:54:05 +02:00
" void foo() { printf( \" %llu %d %ld %I64d %I64u %f %Lf %p \" , f(), f(), f(), f(), f(), f(), f(), f()); } " ) ;
2013-09-29 10:42:47 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned long long'. \n "
" [test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'unsigned long long'. \n "
" [test.cpp:2]: (warning) %I64d in format string (no. 4) requires '__int64' but the argument type is 'unsigned long long'. \n "
" [test.cpp:2]: (warning) %f in format string (no. 6) requires 'double' but the argument type is 'unsigned long long'. \n "
" [test.cpp:2]: (warning) %Lf in format string (no. 7) requires 'long double' but the argument type is 'unsigned long long'. \n "
2013-08-31 06:26:39 +02:00
" [test.cpp:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'unsigned long long'. \n " , errout . str ( ) ) ;
2013-08-24 07:25:50 +02:00
check ( " float f() { return 0; } \n "
2013-09-12 05:54:05 +02:00
" void foo() { printf( \" %f %d %ld %u %lu %I64d %I64u %Lf %p \" , f(), f(), f(), f(), f(), f(), f(), f(), f()); } " ) ;
2013-09-29 10:42:47 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'float'. \n "
" [test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'float'. \n "
" [test.cpp:2]: (warning) %u in format string (no. 4) requires 'unsigned int' but the argument type is 'float'. \n "
" [test.cpp:2]: (warning) %lu in format string (no. 5) requires 'unsigned long' but the argument type is 'float'. \n "
" [test.cpp:2]: (warning) %I64d in format string (no. 6) requires '__int64' but the argument type is 'float'. \n "
" [test.cpp:2]: (warning) %I64u in format string (no. 7) requires 'unsigned __int64' but the argument type is 'float'. \n "
" [test.cpp:2]: (warning) %Lf in format string (no. 8) requires 'long double' but the argument type is 'float'. \n "
2013-08-31 06:26:39 +02:00
" [test.cpp:2]: (warning) %p in format string (no. 9) requires an address but the argument type is 'float'. \n " , errout . str ( ) ) ;
2013-08-24 07:25:50 +02:00
check ( " double f() { return 0; } \n "
2013-09-12 05:54:05 +02:00
" void foo() { printf( \" %f %d %ld %u %lu %I64d %I64u %Lf %p \" , f(), f(), f(), f(), f(), f(), f(), f(), f()); } " ) ;
2013-09-29 10:42:47 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'double'. \n "
" [test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'double'. \n "
" [test.cpp:2]: (warning) %u in format string (no. 4) requires 'unsigned int' but the argument type is 'double'. \n "
" [test.cpp:2]: (warning) %lu in format string (no. 5) requires 'unsigned long' but the argument type is 'double'. \n "
" [test.cpp:2]: (warning) %I64d in format string (no. 6) requires '__int64' but the argument type is 'double'. \n "
" [test.cpp:2]: (warning) %I64u in format string (no. 7) requires 'unsigned __int64' but the argument type is 'double'. \n "
" [test.cpp:2]: (warning) %Lf in format string (no. 8) requires 'long double' but the argument type is 'double'. \n "
2013-08-31 06:26:39 +02:00
" [test.cpp:2]: (warning) %p in format string (no. 9) requires an address but the argument type is 'double'. \n " , errout . str ( ) ) ;
2013-08-24 07:25:50 +02:00
check ( " long double f() { return 0; } \n "
2013-09-12 05:54:05 +02:00
" void foo() { printf( \" %Lf %d %ld %u %lu %I64d %I64u %f %p \" , f(), f(), f(), f(), f(), f(), f(), f(), f()); } " ) ;
2013-09-29 10:42:47 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'long double'. \n "
" [test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'long double'. \n "
" [test.cpp:2]: (warning) %u in format string (no. 4) requires 'unsigned int' but the argument type is 'long double'. \n "
" [test.cpp:2]: (warning) %lu in format string (no. 5) requires 'unsigned long' but the argument type is 'long double'. \n "
" [test.cpp:2]: (warning) %I64d in format string (no. 6) requires '__int64' but the argument type is 'long double'. \n "
" [test.cpp:2]: (warning) %I64u in format string (no. 7) requires 'unsigned __int64' but the argument type is 'long double'. \n "
" [test.cpp:2]: (warning) %f in format string (no. 8) requires 'double' but the argument type is 'long double'. \n "
2013-08-31 06:26:39 +02:00
" [test.cpp:2]: (warning) %p in format string (no. 9) requires an address but the argument type is 'long double'. \n " , errout . str ( ) ) ;
2013-08-24 07:25:50 +02:00
2017-10-20 20:13:14 +02:00
check ( " int f() { return 0; } \n "
" void foo() { printf( \" %I64d %I64u %I64x %d \" , f(), f(), f(), f()); } " ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %I64d in format string (no. 1) requires '__int64' but the argument type is 'signed int'. \n "
" [test.cpp:2]: (warning) %I64u in format string (no. 2) requires 'unsigned __int64' but the argument type is 'signed int'. \n "
" [test.cpp:2]: (warning) %I64x in format string (no. 3) requires 'unsigned __int64' but the argument type is 'signed int'. \n " , errout . str ( ) ) ;
check ( " long long f() { return 0; } \n "
" void foo() { printf( \" %I32d %I32u %I32x %lld \" , f(), f(), f(), f()); } " ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %I32d in format string (no. 1) requires '__int32' but the argument type is 'signed long long'. \n "
" [test.cpp:2]: (warning) %I32u in format string (no. 2) requires 'unsigned __int32' but the argument type is 'signed long long'. \n "
" [test.cpp:2]: (warning) %I32x in format string (no. 3) requires 'unsigned __int32' but the argument type is 'signed long long'. \n " , errout . str ( ) ) ;
check ( " unsigned long long f() { return 0; } \n "
" void foo() { printf( \" %I32d %I32u %I32x %llx \" , f(), f(), f(), f()); } " ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %I32d in format string (no. 1) requires '__int32' but the argument type is 'unsigned long long'. \n "
" [test.cpp:2]: (warning) %I32u in format string (no. 2) requires 'unsigned __int32' but the argument type is 'unsigned long long'. \n "
" [test.cpp:2]: (warning) %I32x in format string (no. 3) requires 'unsigned __int32' but the argument type is 'unsigned long long'. \n " , errout . str ( ) ) ;
check ( " signed char f() { return 0; } \n "
" void foo() { printf( \" %Id %Iu %Ix %hhi \" , f(), f(), f(), f()); } " ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %Id in format string (no. 1) requires 'ptrdiff_t' but the argument type is 'signed char'. \n "
" [test.cpp:2]: (warning) %Iu in format string (no. 2) requires 'size_t' but the argument type is 'signed char'. \n "
" [test.cpp:2]: (warning) %Ix in format string (no. 3) requires 'size_t' but the argument type is 'signed char'. \n " , errout . str ( ) ) ;
check ( " unsigned char f() { return 0; } \n "
" void foo() { printf( \" %Id %Iu %Ix %hho \" , f(), f(), f(), f()); } " ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %Id in format string (no. 1) requires 'ptrdiff_t' but the argument type is 'unsigned char'. \n "
" [test.cpp:2]: (warning) %Iu in format string (no. 2) requires 'size_t' but the argument type is 'unsigned char'. \n "
" [test.cpp:2]: (warning) %Ix in format string (no. 3) requires 'size_t' but the argument type is 'unsigned char'. \n " , errout . str ( ) ) ;
2013-08-24 07:25:50 +02:00
check ( " namespace bar { int f() { return 0; } } \n "
2013-09-12 05:54:05 +02:00
" void foo() { printf( \" %d %u %lu %f %Lf %p \" , bar::f(), bar::f(), bar::f(), bar::f(), bar::f(), bar::f()); } " ) ;
2016-08-14 17:19:14 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
" [test.cpp:2]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'. \n "
" [test.cpp:2]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed int'. \n "
" [test.cpp:2]: (warning) %Lf in format string (no. 5) requires 'long double' but the argument type is 'signed int'. \n "
" [test.cpp:2]: (warning) %p in format string (no. 6) requires an address but the argument type is 'signed int'. \n " , errout . str ( ) ) ;
2013-08-24 22:34:52 +02:00
check ( " struct Fred { int i; } f; \n "
2013-09-12 05:54:05 +02:00
" void foo() { printf( \" %d %u %lu %f %Lf %p \" , f.i, f.i, f.i, f.i, f.i, f.i); } " ) ;
2016-01-31 14:34:26 +01:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
" [test.cpp:2]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'. \n "
" [test.cpp:2]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed int'. \n "
" [test.cpp:2]: (warning) %Lf in format string (no. 5) requires 'long double' but the argument type is 'signed int'. \n "
" [test.cpp:2]: (warning) %p in format string (no. 6) requires an address but the argument type is 'signed int'. \n " , errout . str ( ) ) ;
2013-08-24 07:25:50 +02:00
2013-08-24 22:34:52 +02:00
check ( " struct Fred { unsigned int u; } f; \n "
2013-09-12 05:54:05 +02:00
" void foo() { printf( \" %u %d %ld %f %Lf %p \" , f.u, f.u, f.u, f.u, f.u, f.u); } " ) ;
2013-09-29 10:42:47 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'. \n "
" [test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'unsigned int'. \n "
" [test.cpp:2]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'unsigned int'. \n "
" [test.cpp:2]: (warning) %Lf in format string (no. 5) requires 'long double' but the argument type is 'unsigned int'. \n "
2013-08-31 06:26:39 +02:00
" [test.cpp:2]: (warning) %p in format string (no. 6) requires an address but the argument type is 'unsigned int'. \n " , errout . str ( ) ) ;
2013-08-24 22:34:52 +02:00
check ( " struct Fred { unsigned int ui() { return 0; } } f; \n "
2013-09-12 05:54:05 +02:00
" void foo() { printf( \" %u %d %ld %f %Lf %p \" , f.ui(), f.ui(), f.ui(), f.ui(), f.ui(), f.ui()); } " ) ;
2013-09-29 10:42:47 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'. \n "
" [test.cpp:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'unsigned int'. \n "
" [test.cpp:2]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'unsigned int'. \n "
" [test.cpp:2]: (warning) %Lf in format string (no. 5) requires 'long double' but the argument type is 'unsigned int'. \n "
2013-08-31 06:26:39 +02:00
" [test.cpp:2]: (warning) %p in format string (no. 6) requires an address but the argument type is 'unsigned int'. \n " , errout . str ( ) ) ;
2013-08-25 08:32:10 +02:00
// #4975
check ( " void f(int len, int newline) { \n "
" printf( \" %s \" , newline ? a : str + len); \n "
" printf( \" %s \" , newline + newline); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2016-01-31 14:34:26 +01:00
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %s in format string (no. 1) requires 'char *' but the argument type is 'signed int'. \n " , errout . str ( ) ) ;
2013-08-26 06:03:26 +02:00
check ( " struct Fred { int i; } f; \n "
" struct Fred & bar() { }; \n "
2013-09-12 05:54:05 +02:00
" void foo() { printf( \" %d %u %lu %f %Lf %p \" , bar().i, bar().i, bar().i, bar().i, bar().i, bar().i); } " ) ;
2016-08-14 17:19:14 +02:00
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %Lf in format string (no. 5) requires 'long double' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %p in format string (no. 6) requires an address but the argument type is 'signed int'. \n " , errout . str ( ) ) ;
2013-08-26 06:03:26 +02:00
check ( " struct Fred { int i; } f; \n "
" const struct Fred & bar() { }; \n "
2013-09-12 05:54:05 +02:00
" void foo() { printf( \" %d %u %lu %f %Lf %p \" , bar().i, bar().i, bar().i, bar().i, bar().i, bar().i); } " ) ;
2016-08-14 17:19:14 +02:00
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %Lf in format string (no. 5) requires 'long double' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %p in format string (no. 6) requires an address but the argument type is 'signed int'. \n " , errout . str ( ) ) ;
2013-08-26 06:03:26 +02:00
check ( " struct Fred { int i; } f; \n "
" static const struct Fred & bar() { }; \n "
2013-09-12 05:54:05 +02:00
" void foo() { printf( \" %d %u %lu %f %Lf %p \" , bar().i, bar().i, bar().i, bar().i, bar().i, bar().i); } " ) ;
2016-08-14 17:19:14 +02:00
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %Lf in format string (no. 5) requires 'long double' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %p in format string (no. 6) requires an address but the argument type is 'signed int'. \n " , errout . str ( ) ) ;
2013-08-26 06:03:26 +02:00
check ( " struct Fred { int i; } f[2]; \n "
" struct Fred * bar() { return f; }; \n "
2013-09-12 05:54:05 +02:00
" void foo() { printf( \" %d %u %lu %f %Lf %p \" , bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i); } " ) ;
2016-08-14 17:19:14 +02:00
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %Lf in format string (no. 5) requires 'long double' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %p in format string (no. 6) requires an address but the argument type is 'signed int'. \n " , errout . str ( ) ) ;
2013-08-26 06:03:26 +02:00
check ( " struct Fred { int i; } f[2]; \n "
" const struct Fred * bar() { return f; }; \n "
2013-09-12 05:54:05 +02:00
" void foo() { printf( \" %d %u %lu %f %Lf %p \" , bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i); } " ) ;
2016-08-14 17:19:14 +02:00
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %Lf in format string (no. 5) requires 'long double' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %p in format string (no. 6) requires an address but the argument type is 'signed int'. \n " , errout . str ( ) ) ;
2013-08-26 06:03:26 +02:00
check ( " struct Fred { int i; } f[2]; \n "
" static const struct Fred * bar() { return f; }; \n "
2013-09-12 05:54:05 +02:00
" void foo() { printf( \" %d %u %lu %f %Lf %p \" , bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i, bar()[0].i); } " ) ;
2016-08-14 17:19:14 +02:00
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %Lf in format string (no. 5) requires 'long double' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %p in format string (no. 6) requires an address but the argument type is 'signed int'. \n " , errout . str ( ) ) ;
2013-08-26 06:03:26 +02:00
check ( " struct Fred { int32_t i; } f; \n "
" struct Fred & bar() { }; \n "
2013-09-12 05:54:05 +02:00
" void foo() { printf( \" %d %ld %u %lu %f %Lf \" , bar().i, bar().i, bar().i, bar().i, bar().i, bar().i); } " ) ;
2016-08-14 17:19:14 +02:00
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %ld in format string (no. 2) requires 'long' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %lu in format string (no. 4) requires 'unsigned long' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %f in format string (no. 5) requires 'double' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %Lf in format string (no. 6) requires 'long double' but the argument type is 'signed int'. \n " ,
errout . str ( ) ) ;
2013-08-26 06:03:26 +02:00
2013-08-27 05:46:09 +02:00
// #4984
check ( " void f(double *x) { \n "
" printf( \" %f \" , x[0]); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2013-08-27 05:46:09 +02:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2013-08-28 05:57:40 +02:00
check ( " int array[10]; \n "
" int * foo() { return array; } \n "
" void f() { \n "
" printf( \" %f \" , foo()[0]); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2016-08-14 17:19:14 +02:00
ASSERT_EQUALS ( " [test.cpp:4]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'. \n " , errout . str ( ) ) ;
2013-08-28 05:57:40 +02:00
2013-08-30 05:41:59 +02:00
check ( " struct Base { int length() { } }; \n "
" struct Derived : public Base { }; \n "
" void foo(Derived * d) { \n "
" printf( \" %f \" , d.length()); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2016-08-14 17:19:14 +02:00
ASSERT_EQUALS ( " [test.cpp:4]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'. \n " , errout . str ( ) ) ;
2013-08-30 05:41:59 +02:00
check ( " std::vector<int> v; \n "
" void foo() { \n "
" printf( \" %d %u %f \" , v[0], v[0], v[0]); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2018-04-06 22:26:35 +02:00
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
" [test.cpp:3]: (warning) %f in format string (no. 3) requires 'double' but the argument type is 'signed int'. \n " , errout . str ( ) ) ;
2013-08-30 05:41:59 +02:00
2013-08-31 18:58:55 +02:00
// #4999 (crash)
check ( " int bar(int a); \n "
" void foo() { \n "
" printf( \" %d \" , bar(0)); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2013-08-31 18:58:55 +02:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2013-09-03 05:50:19 +02:00
check ( " std::vector<int> v; \n "
" std::string s; \n "
" void foo() { \n "
" printf( \" %zu %Iu %d %f \" , v.size(), v.size(), v.size(), v.size()); \n "
" printf( \" %zu %Iu %d %f \" , s.size(), s.size(), s.size(), s.size()); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , true , cppcheck : : Platform : : Type : : Win32A ) ;
2019-02-15 13:29:52 +01:00
ASSERT_EQUALS ( " [test.cpp:4]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'. \n "
" [test.cpp:4]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'std::size_t {aka unsigned long}'. \n "
" [test.cpp:5]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'. \n "
" [test.cpp:5]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'std::size_t {aka unsigned long}'. \n " , errout . str ( ) ) ;
2013-09-03 05:50:19 +02:00
check ( " std::vector<int> v; \n "
" std::string s; \n "
" void foo() { \n "
" printf( \" %zu %Iu %d %f \" , v.size(), v.size(), v.size(), v.size()); \n "
" printf( \" %zu %Iu %d %f \" , s.size(), s.size(), s.size(), s.size()); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , true , cppcheck : : Platform : : Type : : Win64 ) ;
2019-02-15 13:29:52 +01:00
ASSERT_EQUALS ( " [test.cpp:4]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long long}'. \n "
" [test.cpp:4]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'std::size_t {aka unsigned long long}'. \n "
" [test.cpp:5]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long long}'. \n "
" [test.cpp:5]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'std::size_t {aka unsigned long long}'. \n " , errout . str ( ) ) ;
2013-09-03 05:50:19 +02:00
check ( " std::vector<int> v; \n "
" std::string s; \n "
" void foo() { \n "
" printf( \" %zu %Iu %d %f \" , v.size(), v.size(), v.size(), v.size()); \n "
" printf( \" %zu %Iu %d %f \" , s.size(), s.size(), s.size(), s.size()); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , true , cppcheck : : Platform : : Type : : Unix32 ) ;
2019-02-15 13:29:52 +01:00
ASSERT_EQUALS ( " [test.cpp:4]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'. \n "
" [test.cpp:4]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'std::size_t {aka unsigned long}'. \n "
" [test.cpp:5]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'. \n "
" [test.cpp:5]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'std::size_t {aka unsigned long}'. \n " , errout . str ( ) ) ;
2013-09-03 05:50:19 +02:00
check ( " std::vector<int> v; \n "
" std::string s; \n "
" void foo() { \n "
" printf( \" %zu %Iu %d %f \" , v.size(), v.size(), v.size(), v.size()); \n "
" printf( \" %zu %Iu %d %f \" , s.size(), s.size(), s.size(), s.size()); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , true , cppcheck : : Platform : : Type : : Unix64 ) ;
2019-02-15 13:29:52 +01:00
ASSERT_EQUALS ( " [test.cpp:4]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'. \n "
" [test.cpp:4]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'std::size_t {aka unsigned long}'. \n "
" [test.cpp:5]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'. \n "
" [test.cpp:5]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'std::size_t {aka unsigned long}'. \n " , errout . str ( ) ) ;
2013-09-03 05:50:19 +02:00
check ( " class Fred : public std::vector<int> {} v; \n "
2013-09-07 07:20:06 +02:00
" std::string s; \n "
2013-09-03 05:50:19 +02:00
" void foo() { \n "
" printf( \" %zu %Iu %d %f \" , v.size(), v.size(), v.size(), v.size()); \n "
" printf( \" %zu %Iu %d %f \" , s.size(), s.size(), s.size(), s.size()); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , true , cppcheck : : Platform : : Type : : Unix64 ) ;
2016-09-11 17:05:01 +02:00
ASSERT_EQUALS ( " [test.cpp:4]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'size_t {aka unsigned long}'. \n "
" [test.cpp:4]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'size_t {aka unsigned long}'. \n "
2019-02-15 13:29:52 +01:00
" [test.cpp:5]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'. \n "
" [test.cpp:5]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'std::size_t {aka unsigned long}'. \n " , errout . str ( ) ) ;
2013-09-07 07:20:06 +02:00
check ( " class Fred : public std::vector<int> {} v; \n "
" void foo() { \n "
" printf( \" %d %u %f \" , v[0], v[0], v[0]); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , true , cppcheck : : Platform : : Type : : Unix64 ) ;
2013-09-29 10:42:47 +02:00
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'int'. \n "
" [test.cpp:3]: (warning) %f in format string (no. 3) requires 'double' but the argument type is 'int'. \n " , errout . str ( ) ) ;
2013-09-03 05:50:19 +02:00
check ( " std::string s; \n "
" void foo() { \n "
" printf( \" %s %p %u %d %f \" , s.c_str(), s.c_str(), s.c_str(), s.c_str(), s.c_str()); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , true , cppcheck : : Platform : : Type : : Unix64 ) ;
2013-09-29 10:42:47 +02:00
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %u in format string (no. 3) requires 'unsigned int' but the argument type is 'const char *'. \n "
" [test.cpp:3]: (warning) %d in format string (no. 4) requires 'int' but the argument type is 'const char *'. \n "
" [test.cpp:3]: (warning) %f in format string (no. 5) requires 'double' but the argument type is 'const char *'. \n " , errout . str ( ) ) ;
2013-09-03 05:50:19 +02:00
2013-09-05 01:46:58 +02:00
check ( " std::vector<int> array; \n "
" char * p = 0; \n "
" char q[] = \" abc \" ; \n "
" char r[10] = { 0 }; \n "
" size_t s; \n "
" void foo() { \n "
" printf( \" %zu %zu \" , array.size(), s); \n "
" printf( \" %u %u %u \" , p, q, r); \n "
" printf( \" %u %u \" , array.size(), s); \n "
" printf( \" %lu %lu \" , array.size(), s); \n "
" printf( \" %llu %llu \" , array.size(), s); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , true , cppcheck : : Platform : : Type : : Unix64 ) ;
2013-09-29 10:42:47 +02:00
ASSERT_EQUALS ( " [test.cpp:8]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'char *'. \n "
" [test.cpp:8]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'char *'. \n "
" [test.cpp:8]: (warning) %u in format string (no. 3) requires 'unsigned int' but the argument type is 'char *'. \n "
2019-02-15 13:29:52 +01:00
" [test.cpp:9]: (portability) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'std::size_t {aka unsigned long}'. \n "
2016-09-11 17:05:01 +02:00
" [test.cpp:9]: (portability) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'size_t {aka unsigned long}'. \n "
2019-02-15 13:29:52 +01:00
" [test.cpp:10]: (portability) %lu in format string (no. 1) requires 'unsigned long' but the argument type is 'std::size_t {aka unsigned long}'. \n "
2016-09-11 17:05:01 +02:00
" [test.cpp:10]: (portability) %lu in format string (no. 2) requires 'unsigned long' but the argument type is 'size_t {aka unsigned long}'. \n "
2019-02-15 13:29:52 +01:00
" [test.cpp:11]: (portability) %llu in format string (no. 1) requires 'unsigned long long' but the argument type is 'std::size_t {aka unsigned long}'. \n "
2016-09-11 17:05:01 +02:00
" [test.cpp:11]: (portability) %llu in format string (no. 2) requires 'unsigned long long' but the argument type is 'size_t {aka unsigned long}'. \n " , errout . str ( ) ) ;
2013-09-05 01:46:58 +02:00
2016-08-14 17:19:14 +02:00
check ( " bool b; bool bf(); \n "
" char c; char cf(); \n "
" signed char sc; signed char scf(); \n "
" unsigned char uc; unsigned char ucf(); \n "
" short s; short sf(); \n "
" unsigned short us; unsigned short usf(); \n "
" size_t st; size_t stf(); \n "
" ptrdiff_t pt; ptrdiff_t ptf(); \n "
" char * pc; char * pcf(); \n "
2013-09-05 06:04:41 +02:00
" char cl[] = \" 123 \" ; \n "
" char ca[3]; \n "
" void foo() { \n "
" printf( \" %td %zd %d %d %d %d %d %d %d %d %d %d %d \" , pt, pt, b, c, sc, uc, s, us, st, pt, pc, cl, ca); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , true , cppcheck : : Platform : : Type : : Unix64 ) ;
2017-03-01 22:33:31 +01:00
ASSERT_EQUALS ( " [test.cpp:13]: (portability) %zd in format string (no. 2) requires 'ssize_t' but the argument type is 'ptrdiff_t {aka signed long}'. \n "
2016-09-11 17:05:01 +02:00
" [test.cpp:13]: (portability) %d in format string (no. 9) requires 'int' but the argument type is 'size_t {aka unsigned long}'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:13]: (portability) %d in format string (no. 10) requires 'int' but the argument type is 'ptrdiff_t {aka signed long}'. \n "
2013-09-29 10:42:47 +02:00
" [test.cpp:13]: (warning) %d in format string (no. 11) requires 'int' but the argument type is 'char *'. \n "
" [test.cpp:13]: (warning) %d in format string (no. 12) requires 'int' but the argument type is 'char *'. \n "
2016-08-14 17:19:14 +02:00
" [test.cpp:13]: (warning) %d in format string (no. 13) requires 'int' but the argument type is 'char *'. \n " , errout . str ( ) ) ;
check ( " bool b; bool bf(); \n "
" char c; char cf(); \n "
" signed char sc; signed char scf(); \n "
" unsigned char uc; unsigned char ucf(); \n "
" short s; short sf(); \n "
" unsigned short us; unsigned short usf(); \n "
" size_t st; size_t stf(); \n "
" ptrdiff_t pt; ptrdiff_t ptf(); \n "
" char * pc; char * pcf(); \n "
" char cl[] = \" 123 \" ; \n "
" char ca[3]; \n "
" void foo() { \n "
" printf( \" %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld \" , b, c, sc, uc, s, us, st, pt, pc, cl, ca); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , true , cppcheck : : Platform : : Type : : Unix64 ) ;
2016-08-14 17:19:14 +02:00
ASSERT_EQUALS ( " [test.cpp:13]: (warning) %ld in format string (no. 1) requires 'long' but the argument type is 'bool'. \n "
" [test.cpp:13]: (warning) %ld in format string (no. 2) requires 'long' but the argument type is 'char'. \n "
" [test.cpp:13]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'signed char'. \n "
" [test.cpp:13]: (warning) %ld in format string (no. 4) requires 'long' but the argument type is 'unsigned char'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:13]: (warning) %ld in format string (no. 5) requires 'long' but the argument type is 'signed short'. \n "
2016-08-14 17:19:14 +02:00
" [test.cpp:13]: (warning) %ld in format string (no. 6) requires 'long' but the argument type is 'unsigned short'. \n "
2016-09-11 17:05:01 +02:00
" [test.cpp:13]: (portability) %ld in format string (no. 7) requires 'long' but the argument type is 'size_t {aka unsigned long}'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:13]: (portability) %ld in format string (no. 8) requires 'long' but the argument type is 'ptrdiff_t {aka signed long}'. \n "
2016-08-14 17:19:14 +02:00
" [test.cpp:13]: (warning) %ld in format string (no. 9) requires 'long' but the argument type is 'char *'. \n "
" [test.cpp:13]: (warning) %ld in format string (no. 10) requires 'long' but the argument type is 'char *'. \n "
" [test.cpp:13]: (warning) %ld in format string (no. 11) requires 'long' but the argument type is 'char *'. \n " , errout . str ( ) ) ;
check ( " bool b; bool bf(); \n "
" char c; char cf(); \n "
" signed char sc; signed char scf(); \n "
" unsigned char uc; unsigned char ucf(); \n "
" short s; short sf(); \n "
" unsigned short us; unsigned short usf(); \n "
" size_t st; size_t stf(); \n "
" ptrdiff_t pt; ptrdiff_t ptf(); \n "
" char * pc; char * pcf(); \n "
" char cl[] = \" 123 \" ; \n "
" char ca[3]; \n "
" void foo() { \n "
" printf( \" %td %zd %d %d %d %d %d %d %d %d %d \" , ptf(), ptf(), bf(), cf(), scf(), ucf(), sf(), usf(), stf(), ptf(), pcf()); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , true , cppcheck : : Platform : : Type : : Unix64 ) ;
2016-09-11 17:05:01 +02:00
ASSERT_EQUALS ( " [test.cpp:13]: (portability) %zd in format string (no. 2) requires 'ssize_t' but the argument type is 'ptrdiff_t {aka signed long}'. \n "
" [test.cpp:13]: (portability) %d in format string (no. 9) requires 'int' but the argument type is 'size_t {aka unsigned long}'. \n "
" [test.cpp:13]: (portability) %d in format string (no. 10) requires 'int' but the argument type is 'ptrdiff_t {aka signed long}'. \n "
2016-08-14 17:19:14 +02:00
" [test.cpp:13]: (warning) %d in format string (no. 11) requires 'int' but the argument type is 'char *'. \n " , errout . str ( ) ) ;
check ( " bool b; bool bf(); \n "
" char c; char cf(); \n "
" signed char sc; signed char scf(); \n "
" unsigned char uc; unsigned char ucf(); \n "
" short s; short sf(); \n "
" unsigned short us; unsigned short usf(); \n "
" size_t st; size_t stf(); \n "
" ptrdiff_t pt; ptrdiff_t ptf(); \n "
" char * pc; char * pcf(); \n "
" char cl[] = \" 123 \" ; \n "
" char ca[3]; \n "
" void foo() { \n "
" printf( \" %ld %ld %ld %ld %ld %ld %ld %ld %ld \" , bf(), cf(), scf(), ucf(), sf(), usf(), stf(), ptf(), pcf()); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , true , cppcheck : : Platform : : Type : : Unix64 ) ;
2016-08-14 17:19:14 +02:00
ASSERT_EQUALS ( " [test.cpp:13]: (warning) %ld in format string (no. 1) requires 'long' but the argument type is 'bool'. \n "
" [test.cpp:13]: (warning) %ld in format string (no. 2) requires 'long' but the argument type is 'char'. \n "
" [test.cpp:13]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'signed char'. \n "
" [test.cpp:13]: (warning) %ld in format string (no. 4) requires 'long' but the argument type is 'unsigned char'. \n "
" [test.cpp:13]: (warning) %ld in format string (no. 5) requires 'long' but the argument type is 'signed short'. \n "
" [test.cpp:13]: (warning) %ld in format string (no. 6) requires 'long' but the argument type is 'unsigned short'. \n "
2016-09-11 17:05:01 +02:00
" [test.cpp:13]: (portability) %ld in format string (no. 7) requires 'long' but the argument type is 'size_t {aka unsigned long}'. \n "
" [test.cpp:13]: (portability) %ld in format string (no. 8) requires 'long' but the argument type is 'ptrdiff_t {aka signed long}'. \n "
2016-08-14 17:19:14 +02:00
" [test.cpp:13]: (warning) %ld in format string (no. 9) requires 'long' but the argument type is 'char *'. \n " , errout . str ( ) ) ;
2013-09-05 06:04:41 +02:00
2013-09-08 20:21:00 +02:00
check ( " struct A {}; \n "
" class B : public std::vector<const int *> {} b; \n "
" class C : public std::vector<const struct A *> {} c; \n "
" std::string s; \n "
" void foo() { \n "
" printf( \" %zu %u \" , b.size(), b.size()); \n "
" printf( \" %p %d \" , b[0], b[0]); \n "
" printf( \" %p %d \" , c[0], c[0]); \n "
" printf( \" %p %d \" , s.c_str(), s.c_str()); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , true , cppcheck : : Platform : : Type : : Unix64 ) ;
2016-09-11 17:05:01 +02:00
ASSERT_EQUALS ( " [test.cpp:6]: (portability) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'size_t {aka unsigned long}'. \n "
2013-09-29 10:42:47 +02:00
" [test.cpp:7]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'const int *'. \n "
" [test.cpp:8]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'const struct A *'. \n "
" [test.cpp:9]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'const char *'. \n " , errout . str ( ) ) ;
2013-09-08 20:21:00 +02:00
check ( " class A : public std::vector<std::string> {} a; \n "
" class B : public std::string {} b; \n "
" std::string s; \n "
" void foo() { \n "
" printf( \" %p %d \" , a[0].c_str(), a[0].c_str()); \n "
" printf( \" %c %p \" , b[0], b[0]); \n "
" printf( \" %c %p \" , s[0], s[0]); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Unix64 ) ;
2013-09-29 10:42:47 +02:00
ASSERT_EQUALS ( " [test.cpp:5]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'const char *'. \n "
2013-09-08 20:21:00 +02:00
" [test.cpp:6]: (warning) %p in format string (no. 2) requires an address but the argument type is 'char'. \n "
" [test.cpp:7]: (warning) %p in format string (no. 2) requires an address but the argument type is 'char'. \n " , errout . str ( ) ) ;
2013-09-24 06:43:03 +02:00
check ( " template <class T> \n "
" struct buffer { \n "
" size_t size(); \n "
" }; \n "
" buffer<int> b; \n "
" void foo() { \n "
" printf( \" %u \" , b.size()); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , true , cppcheck : : Platform : : Type : : Unix64 ) ;
2016-09-11 17:05:01 +02:00
ASSERT_EQUALS ( " [test.cpp:7]: (portability) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'size_t {aka unsigned long}'. \n " , errout . str ( ) ) ;
2013-09-24 06:43:03 +02:00
check ( " DWORD a; \n "
" DWORD_PTR b; \n "
" void foo() { \n "
" printf( \" %u %u \" , a, b); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , true , cppcheck : : Platform : : Type : : Win32A ) ;
2016-09-11 17:05:01 +02:00
ASSERT_EQUALS ( " [test.cpp:4]: (portability) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'DWORD {aka unsigned long}'. \n "
" [test.cpp:4]: (portability) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'DWORD_PTR {aka unsigned long}'. \n " , errout . str ( ) ) ;
2013-09-24 06:43:03 +02:00
check ( " unsigned long a[] = { 1, 2 }; \n "
" void foo() { \n "
" printf( \" %d %d %x \" , a[0], a[0], a[0]); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32A ) ;
2013-09-29 10:42:47 +02:00
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned long'. \n "
" [test.cpp:3]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned long'. \n "
" [test.cpp:3]: (warning) %x in format string (no. 3) requires 'unsigned int' but the argument type is 'unsigned long'. \n " , errout . str ( ) ) ;
2013-09-24 06:43:03 +02:00
2013-09-29 15:25:18 +02:00
check ( " void foo (wchar_t c) { \n " // ticket #5051 false positive
" printf( \" %c \" , c); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win64 ) ;
2013-09-29 15:25:18 +02:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2013-10-02 04:12:46 +02:00
check ( " void foo() { \n "
" printf( \" %f %d \" , static_cast<int>(1.0f), reinterpret_cast<const void *>(0)); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2017-02-25 18:22:14 +01:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'. \n "
2013-10-02 04:12:46 +02:00
" [test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'const void *'. \n " , errout . str ( ) ) ;
2013-10-05 16:47:06 +02:00
check ( " void foo() { \n "
" UNKNOWN * u; \n "
" printf( \" %d %x %u %f \" , u[i], u[i], u[i], u[i]); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2013-10-05 16:47:06 +02:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo() { \n "
" long * l; \n "
" printf( \" %d %x %u %f \" , l[i], l[i], l[i], l[i]); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2016-01-31 14:34:26 +01:00
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'signed long'. \n "
" [test.cpp:3]: (warning) %x in format string (no. 2) requires 'unsigned int' but the argument type is 'signed long'. \n "
" [test.cpp:3]: (warning) %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed long'. \n "
" [test.cpp:3]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed long'. \n " , errout . str ( ) ) ;
2013-10-05 16:47:06 +02:00
2013-10-27 10:48:49 +01:00
check ( " void f() { \n " // #5104
" myvector<unsigned short> v1(1,0); \n "
2017-05-18 17:23:26 +02:00
" printf( \" %d \" ,v1[0]); \n "
2013-10-27 10:48:49 +01:00
" myvector<int> v2(1,0); \n "
2017-05-18 17:23:26 +02:00
" printf( \" %d \" ,v2[0]); \n "
2013-10-27 10:48:49 +01:00
" myvector<unsigned int> v3(1,0); \n "
2017-05-18 17:23:26 +02:00
" printf( \" %u \" ,v3[0]); \n "
2013-10-27 10:48:49 +01:00
" myvector<unsigned int> v4(1,0); \n "
2017-05-18 17:23:26 +02:00
" printf( \" %x \" ,v4[0]); \n "
2013-10-27 10:48:49 +01:00
" myvector<double> v5(1,0); \n "
2017-05-18 17:23:26 +02:00
" printf( \" %f \" ,v5[0]); \n "
2013-10-27 10:48:49 +01:00
" myvector<bool> v6(1,0); \n "
2017-05-18 17:23:26 +02:00
" printf( \" %u \" ,v6[0]); \n "
2013-10-27 10:48:49 +01:00
" myvector<char *> v7(1,0); \n "
2017-05-18 17:23:26 +02:00
" printf( \" %s \" ,v7[0]); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2013-10-27 10:48:49 +01:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2013-11-08 12:44:05 +01:00
check ( " std::vector<char> v; \n " // #5151
" void foo() { \n "
" printf( \" %c %u %f \" , v.at(32), v.at(32), v.at(32)); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2013-11-08 12:44:05 +01:00
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'char'. \n "
" [test.cpp:3]: (warning) %f in format string (no. 3) requires 'double' but the argument type is 'char'. \n " , errout . str ( ) ) ;
2013-11-23 08:40:35 +01:00
// #5195 (segmentation fault)
check ( " void T::a(const std::vector<double>& vx) { \n "
" printf( \" %f \" , vx.at(0)); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2013-11-23 08:40:35 +01:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2014-04-10 17:25:11 +02:00
// #5486
check ( " void foo() { \n "
" ssize_t test = 0; \n "
" printf( \" %zd \" , test); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2014-04-10 17:25:11 +02:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2014-07-28 09:16:35 +02:00
// #6009
check ( " extern std::string StringByReturnValue(); \n "
" extern int IntByReturnValue(); \n "
" void MyFunction() { \n "
" printf( \" %s - %s \" , StringByReturnValue(), IntByReturnValue() ); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2014-07-28 09:16:35 +02:00
ASSERT_EQUALS ( " [test.cpp:4]: (warning) %s in format string (no. 1) requires 'char *' but the argument type is 'std::string'. \n "
2016-08-14 17:19:14 +02:00
" [test.cpp:4]: (warning) %s in format string (no. 2) requires 'char *' but the argument type is 'signed int'. \n " , errout . str ( ) ) ;
2014-07-28 09:16:35 +02:00
2014-10-20 06:33:36 +02:00
check ( " template <class T, size_t S> \n "
" struct Array { \n "
" T data[S]; \n "
" T & operator [] (size_t i) { return data[i]; } \n "
" }; \n "
" void foo() { \n "
" Array<int, 10> array1; \n "
" Array<float, 10> array2; \n "
" printf( \" %u %u \" , array1[0], array2[0]); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2014-10-20 06:33:36 +02:00
ASSERT_EQUALS ( " [test.cpp:9]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'int'. \n "
" [test.cpp:9]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'float'. \n " , errout . str ( ) ) ;
2016-05-28 15:36:13 +02:00
// Ticket #7445
check ( " struct S { unsigned short x; } s = {0}; \n "
" void foo() { \n "
" printf( \" %d \" , s.x); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2016-07-16 10:33:46 +02:00
// Ticket #7601
check ( " void foo(int i, unsigned int ui, long long ll, unsigned long long ull) { \n "
" printf( \" %Ld %Lu %Ld %Lu \" , i, ui, ll, ull); \n "
" } " ) ;
2017-03-01 22:33:31 +01:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %Ld in format string (no. 1) requires 'long long' but the argument type is 'signed int'. \n "
2016-07-16 10:33:46 +02:00
" [test.cpp:2]: (warning) %Lu in format string (no. 2) requires 'unsigned long long' but the argument type is 'unsigned int'. \n " , errout . str ( ) ) ;
2016-08-24 12:47:11 +02:00
check ( " void foo(char c, unsigned char uc, short s, unsigned short us, int i, unsigned int ui, long l, unsigned long ul) { \n "
" printf( \" %hhd %hhd %hhd %hhd %hhd %hhd %hhd %hhd \" , c, uc, s, us, i, ui, l, ul); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %hhd in format string (no. 2) requires 'char' but the argument type is 'unsigned char'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:2]: (warning) %hhd in format string (no. 3) requires 'char' but the argument type is 'signed short'. \n "
2016-08-24 12:47:11 +02:00
" [test.cpp:2]: (warning) %hhd in format string (no. 4) requires 'char' but the argument type is 'unsigned short'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:2]: (warning) %hhd in format string (no. 5) requires 'char' but the argument type is 'signed int'. \n "
2016-08-24 12:47:11 +02:00
" [test.cpp:2]: (warning) %hhd in format string (no. 6) requires 'char' but the argument type is 'unsigned int'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:2]: (warning) %hhd in format string (no. 7) requires 'char' but the argument type is 'signed long'. \n "
2016-08-24 12:47:11 +02:00
" [test.cpp:2]: (warning) %hhd in format string (no. 8) requires 'char' but the argument type is 'unsigned long'. \n " , errout . str ( ) ) ;
check ( " void foo(char c, unsigned char uc, short s, unsigned short us, int i, unsigned int ui, long l, unsigned long ul) { \n "
" printf( \" %hhu %hhu %hhu %hhu %hhu %hhu %hhu %hhu \" , c, uc, s, us, i, ui, l, ul); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %hhu in format string (no. 1) requires 'unsigned char' but the argument type is 'char'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:2]: (warning) %hhu in format string (no. 3) requires 'unsigned char' but the argument type is 'signed short'. \n "
2016-08-24 12:47:11 +02:00
" [test.cpp:2]: (warning) %hhu in format string (no. 4) requires 'unsigned char' but the argument type is 'unsigned short'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:2]: (warning) %hhu in format string (no. 5) requires 'unsigned char' but the argument type is 'signed int'. \n "
2016-08-24 12:47:11 +02:00
" [test.cpp:2]: (warning) %hhu in format string (no. 6) requires 'unsigned char' but the argument type is 'unsigned int'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:2]: (warning) %hhu in format string (no. 7) requires 'unsigned char' but the argument type is 'signed long'. \n "
2016-08-24 12:47:11 +02:00
" [test.cpp:2]: (warning) %hhu in format string (no. 8) requires 'unsigned char' but the argument type is 'unsigned long'. \n " , errout . str ( ) ) ;
check ( " void foo(char c, unsigned char uc, short s, unsigned short us, int i, unsigned int ui, long l, unsigned long ul) { \n "
" printf( \" %hhx %hhx %hhx %hhx %hhx %hhx %hhx %hhx \" , c, uc, s, us, i, ui, l, ul); \n "
" } " ) ;
2017-11-21 20:14:48 +01:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %hhx in format string (no. 1) requires 'unsigned char' but the argument type is 'char'. \n "
" [test.cpp:2]: (warning) %hhx in format string (no. 3) requires 'unsigned char' but the argument type is 'signed short'. \n "
2016-08-24 12:47:11 +02:00
" [test.cpp:2]: (warning) %hhx in format string (no. 4) requires 'unsigned char' but the argument type is 'unsigned short'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:2]: (warning) %hhx in format string (no. 5) requires 'unsigned char' but the argument type is 'signed int'. \n "
2016-08-24 12:47:11 +02:00
" [test.cpp:2]: (warning) %hhx in format string (no. 6) requires 'unsigned char' but the argument type is 'unsigned int'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:2]: (warning) %hhx in format string (no. 7) requires 'unsigned char' but the argument type is 'signed long'. \n "
2016-08-24 12:47:11 +02:00
" [test.cpp:2]: (warning) %hhx in format string (no. 8) requires 'unsigned char' but the argument type is 'unsigned long'. \n " , errout . str ( ) ) ;
check ( " void foo(char c, unsigned char uc, short s, unsigned short us, int i, unsigned int ui, long l, unsigned long ul) { \n "
" printf( \" %hd %hd %hd %hd %hd %hd %hd %hd \" , c, uc, s, us, i, ui, l, ul); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %hd in format string (no. 1) requires 'short' but the argument type is 'char'. \n "
" [test.cpp:2]: (warning) %hd in format string (no. 2) requires 'short' but the argument type is 'unsigned char'. \n "
" [test.cpp:2]: (warning) %hd in format string (no. 4) requires 'short' but the argument type is 'unsigned short'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:2]: (warning) %hd in format string (no. 5) requires 'short' but the argument type is 'signed int'. \n "
2016-08-24 12:47:11 +02:00
" [test.cpp:2]: (warning) %hd in format string (no. 6) requires 'short' but the argument type is 'unsigned int'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:2]: (warning) %hd in format string (no. 7) requires 'short' but the argument type is 'signed long'. \n "
2016-08-24 12:47:11 +02:00
" [test.cpp:2]: (warning) %hd in format string (no. 8) requires 'short' but the argument type is 'unsigned long'. \n " , errout . str ( ) ) ;
check ( " void foo(char c, unsigned char uc, short s, unsigned short us, int i, unsigned int ui, long l, unsigned long ul) { \n "
" printf( \" %hu %hu %hu %hu %hu %hu %hu %hu \" , c, uc, s, us, i, ui, l, ul); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %hu in format string (no. 1) requires 'unsigned short' but the argument type is 'char'. \n "
" [test.cpp:2]: (warning) %hu in format string (no. 2) requires 'unsigned short' but the argument type is 'unsigned char'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:2]: (warning) %hu in format string (no. 3) requires 'unsigned short' but the argument type is 'signed short'. \n "
" [test.cpp:2]: (warning) %hu in format string (no. 5) requires 'unsigned short' but the argument type is 'signed int'. \n "
2016-08-24 12:47:11 +02:00
" [test.cpp:2]: (warning) %hu in format string (no. 6) requires 'unsigned short' but the argument type is 'unsigned int'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:2]: (warning) %hu in format string (no. 7) requires 'unsigned short' but the argument type is 'signed long'. \n "
2016-08-24 12:47:11 +02:00
" [test.cpp:2]: (warning) %hu in format string (no. 8) requires 'unsigned short' but the argument type is 'unsigned long'. \n " , errout . str ( ) ) ;
check ( " void foo(char c, unsigned char uc, short s, unsigned short us, int i, unsigned int ui, long l, unsigned long ul) { \n "
" printf( \" %hx %hx %hx %hx %hx %hx %hx %hx \" , c, uc, s, us, i, ui, l, ul); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %hx in format string (no. 1) requires 'unsigned short' but the argument type is 'char'. \n "
" [test.cpp:2]: (warning) %hx in format string (no. 2) requires 'unsigned short' but the argument type is 'unsigned char'. \n "
2017-11-21 20:17:02 +01:00
" [test.cpp:2]: (warning) %hx in format string (no. 3) requires 'unsigned short' but the argument type is 'signed short'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:2]: (warning) %hx in format string (no. 5) requires 'unsigned short' but the argument type is 'signed int'. \n "
2016-08-24 12:47:11 +02:00
" [test.cpp:2]: (warning) %hx in format string (no. 6) requires 'unsigned short' but the argument type is 'unsigned int'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:2]: (warning) %hx in format string (no. 7) requires 'unsigned short' but the argument type is 'signed long'. \n "
2016-08-24 12:47:11 +02:00
" [test.cpp:2]: (warning) %hx in format string (no. 8) requires 'unsigned short' but the argument type is 'unsigned long'. \n " , errout . str ( ) ) ;
2017-02-25 18:22:14 +01:00
// #7837 - Use ValueType for function call
check ( " struct S { \n "
" double (* f)(double); \n "
" }; \n "
" \n "
" void foo(struct S x) { \n "
" printf( \" %f \" , x.f(4.0)); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2022-01-27 19:43:52 +01:00
check ( " void f() { \n "
" printf( \" %lu \" , sizeof(char)); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , true , cppcheck : : Platform : : Type : : Win64 ) ;
2022-01-27 19:43:52 +01:00
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 ( ) ) ;
2012-05-20 21:26:48 +02:00
}
2013-07-21 08:35:01 +02:00
2017-11-10 21:53:53 +01:00
void testPrintfArgumentVariables ( ) {
TEST_PRINTF_NOWARN ( " %u " , " unsigned int " , " bool " ) ;
TEST_PRINTF_WARN ( " %u " , " unsigned int " , " char " ) ;
TEST_PRINTF_WARN ( " %u " , " unsigned int " , " signed char " ) ;
TEST_PRINTF_NOWARN ( " %u " , " unsigned int " , " unsigned char " ) ;
TEST_PRINTF_WARN ( " %u " , " unsigned int " , " signed short " ) ;
TEST_PRINTF_NOWARN ( " %u " , " unsigned int " , " unsigned short " ) ;
TEST_PRINTF_WARN ( " %u " , " unsigned int " , " signed int " ) ;
TEST_PRINTF_NOWARN ( " %u " , " unsigned int " , " unsigned int " ) ;
TEST_PRINTF_WARN ( " %u " , " unsigned int " , " signed long " ) ;
TEST_PRINTF_WARN ( " %u " , " unsigned int " , " unsigned long " ) ;
TEST_PRINTF_WARN ( " %u " , " unsigned int " , " signed long long " ) ;
TEST_PRINTF_WARN ( " %u " , " unsigned int " , " unsigned long long " ) ;
TEST_PRINTF_WARN ( " %u " , " unsigned int " , " float " ) ;
TEST_PRINTF_WARN ( " %u " , " unsigned int " , " double " ) ;
TEST_PRINTF_WARN ( " %u " , " unsigned int " , " long double " ) ;
TEST_PRINTF_WARN ( " %u " , " unsigned int " , " void * " ) ;
TEST_PRINTF_WARN_AKA ( " %u " , " unsigned int " , " size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %u " , " unsigned int " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %u " , " unsigned int " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %u " , " unsigned int " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %u " , " unsigned int " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %u " , " unsigned int " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %u " , " unsigned int " , " intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %u " , " unsigned int " , " uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_PRINTF_WARN_AKA_CPP ( " %u " , " unsigned int " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %u " , " unsigned int " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %u " , " unsigned int " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %u " , " unsigned int " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %u " , " unsigned int " , " std::uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %u " , " unsigned int " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %u " , " unsigned int " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-10 21:53:53 +01:00
TEST_PRINTF_NOWARN ( " %x " , " unsigned int " , " bool " ) ;
//TODO TEST_PRINTF_WARN("%x", "unsigned int", "char");
//TODO TEST_PRINTF_WARN("%x", "unsigned int", "signed char");
TEST_PRINTF_NOWARN ( " %x " , " unsigned int " , " unsigned char " ) ;
//TODO TEST_PRINTF_WARN("%x", "unsigned int", "signed short");
TEST_PRINTF_NOWARN ( " %x " , " unsigned int " , " unsigned short " ) ;
//TODO TEST_PRINTF_WARN("%x", "unsigned int", "signed int");
TEST_PRINTF_NOWARN ( " %x " , " unsigned int " , " unsigned int " ) ;
TEST_PRINTF_WARN ( " %x " , " unsigned int " , " signed long " ) ;
TEST_PRINTF_WARN ( " %x " , " unsigned int " , " unsigned long " ) ;
TEST_PRINTF_WARN ( " %x " , " unsigned int " , " signed long long " ) ;
TEST_PRINTF_WARN ( " %x " , " unsigned int " , " unsigned long long " ) ;
TEST_PRINTF_WARN ( " %x " , " unsigned int " , " float " ) ;
TEST_PRINTF_WARN ( " %x " , " unsigned int " , " double " ) ;
TEST_PRINTF_WARN ( " %x " , " unsigned int " , " long double " ) ;
TEST_PRINTF_WARN ( " %x " , " unsigned int " , " void * " ) ;
TEST_PRINTF_WARN_AKA ( " %x " , " unsigned int " , " size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %x " , " unsigned int " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %x " , " unsigned int " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %x " , " unsigned int " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %x " , " unsigned int " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %x " , " unsigned int " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %x " , " unsigned int " , " intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %x " , " unsigned int " , " uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_PRINTF_WARN_AKA_CPP ( " %x " , " unsigned int " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %x " , " unsigned int " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %x " , " unsigned int " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %x " , " unsigned int " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %x " , " unsigned int " , " std::uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %x " , " unsigned int " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %x " , " unsigned int " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-10 21:53:53 +01:00
TEST_PRINTF_WARN ( " %lu " , " unsigned long " , " bool " ) ;
TEST_PRINTF_WARN ( " %lu " , " unsigned long " , " char " ) ;
TEST_PRINTF_WARN ( " %lu " , " unsigned long " , " signed char " ) ;
TEST_PRINTF_WARN ( " %lu " , " unsigned long " , " unsigned char " ) ;
TEST_PRINTF_WARN ( " %lu " , " unsigned long " , " signed short " ) ;
TEST_PRINTF_WARN ( " %lu " , " unsigned long " , " unsigned short " ) ;
TEST_PRINTF_WARN ( " %lu " , " unsigned long " , " signed int " ) ;
TEST_PRINTF_WARN ( " %lu " , " unsigned long " , " unsigned int " ) ;
TEST_PRINTF_WARN ( " %lu " , " unsigned long " , " signed long " ) ;
TEST_PRINTF_NOWARN ( " %lu " , " unsigned long " , " unsigned long " ) ;
TEST_PRINTF_WARN ( " %lu " , " unsigned long " , " signed long long " ) ;
TEST_PRINTF_WARN ( " %lu " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN ( " %lu " , " unsigned long " , " float " ) ;
TEST_PRINTF_WARN ( " %lu " , " unsigned long " , " double " ) ;
TEST_PRINTF_WARN ( " %lu " , " unsigned long " , " long double " ) ;
TEST_PRINTF_WARN ( " %lu " , " unsigned long " , " void * " ) ;
TEST_PRINTF_WARN_AKA ( " %lu " , " unsigned long " , " size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %lu " , " unsigned long " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %lu " , " unsigned long " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_WIN64 ( " %lu " , " unsigned long " , " unsigned ptrdiff_t " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %lu " , " unsigned long " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %lu " , " unsigned long " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %lu " , " unsigned long " , " intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_WIN64 ( " %lu " , " unsigned long " , " uintptr_t " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_PRINTF_WARN_AKA_CPP ( " %lu " , " unsigned long " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %lu " , " unsigned long " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %lu " , " unsigned long " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %lu " , " unsigned long " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP_WIN64 ( " %lu " , " unsigned long " , " std::uintmax_t " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %lu " , " unsigned long " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP_WIN64 ( " %lu " , " unsigned long " , " std::uintptr_t " , " unsigned long long " ) ;
2017-11-10 21:53:53 +01:00
TEST_PRINTF_WARN ( " %lx " , " unsigned long " , " bool " ) ;
TEST_PRINTF_WARN ( " %lx " , " unsigned long " , " char " ) ;
TEST_PRINTF_WARN ( " %lx " , " unsigned long " , " signed char " ) ;
TEST_PRINTF_WARN ( " %lx " , " unsigned long " , " unsigned char " ) ;
TEST_PRINTF_WARN ( " %lx " , " unsigned long " , " signed short " ) ;
TEST_PRINTF_WARN ( " %lx " , " unsigned long " , " unsigned short " ) ;
TEST_PRINTF_WARN ( " %lx " , " unsigned long " , " signed int " ) ;
TEST_PRINTF_WARN ( " %lx " , " unsigned long " , " unsigned int " ) ;
//TODO TEST_PRINTF_WARN("%lx","unsigned long","signed long");
TEST_PRINTF_NOWARN ( " %lx " , " unsigned long " , " unsigned long " ) ;
TEST_PRINTF_WARN ( " %lx " , " unsigned long " , " signed long long " ) ;
TEST_PRINTF_WARN ( " %lx " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN ( " %lx " , " unsigned long " , " float " ) ;
TEST_PRINTF_WARN ( " %lx " , " unsigned long " , " double " ) ;
TEST_PRINTF_WARN ( " %lx " , " unsigned long " , " long double " ) ;
TEST_PRINTF_WARN ( " %lx " , " unsigned long " , " void * " ) ;
2017-11-20 20:56:33 +01:00
TEST_PRINTF_WARN_AKA ( " %lx " , " unsigned long " , " size_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-10 21:53:53 +01:00
TEST_PRINTF_WARN_AKA_WIN64 ( " %lx " , " unsigned long " , " ssize_t " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_WIN64 ( " %lx " , " unsigned long " , " ptrdiff_t " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_WIN64 ( " %lx " , " unsigned long " , " unsigned ptrdiff_t " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_WIN64 ( " %lx " , " unsigned long " , " intmax_t " , " signed long long " ) ;
2017-11-20 20:56:33 +01:00
TEST_PRINTF_WARN_AKA ( " %lx " , " unsigned long " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-10 21:53:53 +01:00
TEST_PRINTF_WARN_AKA_WIN64 ( " %lx " , " unsigned long " , " intptr_t " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_WIN64 ( " %lx " , " unsigned long " , " uintptr_t " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_PRINTF_WARN_AKA_CPP ( " %lx " , " unsigned long " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_CPP_WIN64 ( " %lx " , " unsigned long " , " std::ssize_t " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP_WIN64 ( " %lx " , " unsigned long " , " std::ptrdiff_t " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP_WIN64 ( " %lx " , " unsigned long " , " std::intmax_t " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP_WIN64 ( " %lx " , " unsigned long " , " std::uintmax_t " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_CPP_WIN64 ( " %lx " , " unsigned long " , " std::intptr_t " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP_WIN64 ( " %lx " , " unsigned long " , " std::uintptr_t " , " unsigned long long " ) ;
2017-11-10 21:53:53 +01:00
TEST_PRINTF_WARN ( " %llu " , " unsigned long long " , " bool " ) ;
TEST_PRINTF_WARN ( " %llu " , " unsigned long long " , " char " ) ;
TEST_PRINTF_WARN ( " %llu " , " unsigned long long " , " signed char " ) ;
TEST_PRINTF_WARN ( " %llu " , " unsigned long long " , " unsigned char " ) ;
TEST_PRINTF_WARN ( " %llu " , " unsigned long long " , " signed short " ) ;
TEST_PRINTF_WARN ( " %llu " , " unsigned long long " , " unsigned short " ) ;
TEST_PRINTF_WARN ( " %llu " , " unsigned long long " , " signed int " ) ;
TEST_PRINTF_WARN ( " %llu " , " unsigned long long " , " unsigned int " ) ;
TEST_PRINTF_WARN ( " %llu " , " unsigned long long " , " signed long " ) ;
TEST_PRINTF_WARN ( " %llu " , " unsigned long long " , " unsigned long " ) ;
TEST_PRINTF_WARN ( " %llu " , " unsigned long long " , " signed long long " ) ;
TEST_PRINTF_NOWARN ( " %llu " , " unsigned long long " , " unsigned long long " ) ;
TEST_PRINTF_WARN ( " %llu " , " unsigned long long " , " float " ) ;
TEST_PRINTF_WARN ( " %llu " , " unsigned long long " , " double " ) ;
TEST_PRINTF_WARN ( " %llu " , " unsigned long long " , " long double " ) ;
TEST_PRINTF_WARN ( " %llu " , " unsigned long long " , " void * " ) ;
TEST_PRINTF_WARN_AKA ( " %llu " , " unsigned long long " , " size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %llu " , " unsigned long long " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %llu " , " unsigned long long " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_WIN32 ( " %llu " , " unsigned long long " , " unsigned ptrdiff_t " , " unsigned long " ) ;
TEST_PRINTF_WARN_AKA ( " %llu " , " unsigned long long " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %llu " , " unsigned long long " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %llu " , " unsigned long long " , " intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_WIN32 ( " %llu " , " unsigned long long " , " uintptr_t " , " unsigned long " ) ;
2023-02-23 22:53:39 +01:00
TEST_PRINTF_WARN_AKA_CPP ( " %llu " , " unsigned long long " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %llu " , " unsigned long long " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %llu " , " unsigned long long " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %llu " , " unsigned long long " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP_WIN32 ( " %llu " , " unsigned long long " , " std::uintmax_t " , " unsigned long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %llu " , " unsigned long long " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP_WIN32 ( " %llu " , " unsigned long long " , " std::uintptr_t " , " unsigned long " ) ;
2017-11-10 21:53:53 +01:00
TEST_PRINTF_WARN ( " %llx " , " unsigned long long " , " bool " ) ;
TEST_PRINTF_WARN ( " %llx " , " unsigned long long " , " char " ) ;
TEST_PRINTF_WARN ( " %llx " , " unsigned long long " , " signed char " ) ;
TEST_PRINTF_WARN ( " %llx " , " unsigned long long " , " unsigned char " ) ;
TEST_PRINTF_WARN ( " %llx " , " unsigned long long " , " signed short " ) ;
TEST_PRINTF_WARN ( " %llx " , " unsigned long long " , " unsigned short " ) ;
TEST_PRINTF_WARN ( " %llx " , " unsigned long long " , " signed int " ) ;
TEST_PRINTF_WARN ( " %llx " , " unsigned long long " , " unsigned int " ) ;
TEST_PRINTF_WARN ( " %llx " , " unsigned long long " , " signed long " ) ;
TEST_PRINTF_WARN ( " %llx " , " unsigned long long " , " unsigned long " ) ;
//TODO TEST_PRINTF_WARN("%llx","unsigned long long","signed long long");
TEST_PRINTF_NOWARN ( " %llx " , " unsigned long long " , " unsigned long long " ) ;
TEST_PRINTF_WARN ( " %llx " , " unsigned long long " , " float " ) ;
TEST_PRINTF_WARN ( " %llx " , " unsigned long long " , " double " ) ;
TEST_PRINTF_WARN ( " %llx " , " unsigned long long " , " long double " ) ;
TEST_PRINTF_WARN ( " %llx " , " unsigned long long " , " void * " ) ;
2017-11-20 20:56:33 +01:00
TEST_PRINTF_WARN_AKA ( " %llx " , " unsigned long long " , " size_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-10 21:53:53 +01:00
TEST_PRINTF_WARN_AKA_WIN32 ( " %llx " , " unsigned long long " , " ssize_t " , " signed long " ) ;
TEST_PRINTF_WARN_AKA_WIN32 ( " %llx " , " unsigned long long " , " ptrdiff_t " , " signed long " ) ;
TEST_PRINTF_WARN_AKA_WIN32 ( " %llx " , " unsigned long long " , " unsigned ptrdiff_t " , " unsigned long " ) ;
TEST_PRINTF_WARN_AKA_WIN32 ( " %llx " , " unsigned long long " , " intmax_t " , " signed long " ) ;
2017-11-20 20:56:33 +01:00
TEST_PRINTF_WARN_AKA ( " %llx " , " unsigned long long " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-10 21:53:53 +01:00
TEST_PRINTF_WARN_AKA_WIN32 ( " %llx " , " unsigned long long " , " intptr_t " , " signed long " ) ;
TEST_PRINTF_WARN_AKA_WIN32 ( " %llx " , " unsigned long long " , " uintptr_t " , " unsigned long " ) ;
2023-02-23 22:53:39 +01:00
TEST_PRINTF_WARN_AKA_CPP ( " %llx " , " unsigned long long " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_CPP_WIN32 ( " %llx " , " unsigned long long " , " std::ssize_t " , " signed long " ) ;
TEST_PRINTF_WARN_AKA_CPP_WIN32 ( " %llx " , " unsigned long long " , " std::ptrdiff_t " , " signed long " ) ;
TEST_PRINTF_WARN_AKA_CPP_WIN32 ( " %llx " , " unsigned long long " , " std::intmax_t " , " signed long " ) ;
TEST_PRINTF_WARN_AKA_CPP_WIN32 ( " %llx " , " unsigned long long " , " std::uintmax_t " , " unsigned long " ) ;
TEST_PRINTF_WARN_AKA_CPP_WIN32 ( " %llx " , " unsigned long long " , " std::intptr_t " , " signed long " ) ;
TEST_PRINTF_WARN_AKA_CPP_WIN32 ( " %llx " , " unsigned long long " , " std::uintptr_t " , " unsigned long " ) ;
2017-11-10 21:53:53 +01:00
TEST_PRINTF_WARN ( " %hu " , " unsigned short " , " bool " ) ;
TEST_PRINTF_WARN ( " %hu " , " unsigned short " , " char " ) ;
TEST_PRINTF_WARN ( " %hu " , " unsigned short " , " signed char " ) ;
TEST_PRINTF_WARN ( " %hu " , " unsigned short " , " unsigned char " ) ;
TEST_PRINTF_WARN ( " %hu " , " unsigned short " , " signed short " ) ;
TEST_PRINTF_NOWARN ( " %hu " , " unsigned short " , " unsigned short " ) ;
TEST_PRINTF_WARN ( " %hu " , " unsigned short " , " signed int " ) ;
TEST_PRINTF_WARN ( " %hu " , " unsigned short " , " unsigned int " ) ;
TEST_PRINTF_WARN ( " %hu " , " unsigned short " , " signed long " ) ;
TEST_PRINTF_WARN ( " %hu " , " unsigned short " , " unsigned long " ) ;
TEST_PRINTF_WARN ( " %hu " , " unsigned short " , " signed long long " ) ;
TEST_PRINTF_WARN ( " %hu " , " unsigned short " , " unsigned long long " ) ;
TEST_PRINTF_WARN ( " %hu " , " unsigned short " , " float " ) ;
TEST_PRINTF_WARN ( " %hu " , " unsigned short " , " double " ) ;
TEST_PRINTF_WARN ( " %hu " , " unsigned short " , " long double " ) ;
TEST_PRINTF_WARN ( " %hu " , " unsigned short " , " void * " ) ;
TEST_PRINTF_WARN_AKA ( " %hu " , " unsigned short " , " size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %hu " , " unsigned short " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %hu " , " unsigned short " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %hu " , " unsigned short " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %hu " , " unsigned short " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %hu " , " unsigned short " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_PRINTF_WARN_AKA_CPP ( " %hu " , " unsigned short " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %hu " , " unsigned short " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %hu " , " unsigned short " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %hu " , " unsigned short " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %hu " , " unsigned short " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-10 21:53:53 +01:00
TEST_PRINTF_WARN ( " %hx " , " unsigned short " , " bool " ) ;
TEST_PRINTF_WARN ( " %hx " , " unsigned short " , " char " ) ;
TEST_PRINTF_WARN ( " %hx " , " unsigned short " , " signed char " ) ;
TEST_PRINTF_WARN ( " %hx " , " unsigned short " , " unsigned char " ) ;
2017-11-21 20:17:02 +01:00
TEST_PRINTF_WARN ( " %hx " , " unsigned short " , " signed short " ) ;
2017-11-10 21:53:53 +01:00
TEST_PRINTF_NOWARN ( " %hx " , " unsigned short " , " unsigned short " ) ;
TEST_PRINTF_WARN ( " %hx " , " unsigned short " , " signed int " ) ;
TEST_PRINTF_WARN ( " %hx " , " unsigned short " , " unsigned int " ) ;
TEST_PRINTF_WARN ( " %hx " , " unsigned short " , " signed long " ) ;
TEST_PRINTF_WARN ( " %hx " , " unsigned short " , " unsigned long " ) ;
TEST_PRINTF_WARN ( " %hx " , " unsigned short " , " signed long long " ) ;
TEST_PRINTF_WARN ( " %hx " , " unsigned short " , " unsigned long long " ) ;
TEST_PRINTF_WARN ( " %hx " , " unsigned short " , " float " ) ;
TEST_PRINTF_WARN ( " %hx " , " unsigned short " , " double " ) ;
TEST_PRINTF_WARN ( " %hx " , " unsigned short " , " long double " ) ;
TEST_PRINTF_WARN ( " %hx " , " unsigned short " , " void * " ) ;
TEST_PRINTF_WARN_AKA ( " %hx " , " unsigned short " , " size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %hx " , " unsigned short " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %hx " , " unsigned short " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %hx " , " unsigned short " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %hx " , " unsigned short " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %hx " , " unsigned short " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_PRINTF_WARN_AKA_CPP ( " %hx " , " unsigned short " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %hx " , " unsigned short " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %hx " , " unsigned short " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %hx " , " unsigned short " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %hx " , " unsigned short " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-10 21:53:53 +01:00
TEST_PRINTF_WARN ( " %hhu " , " unsigned char " , " bool " ) ;
TEST_PRINTF_WARN ( " %hhu " , " unsigned char " , " char " ) ;
TEST_PRINTF_WARN ( " %hhu " , " unsigned char " , " signed char " ) ;
TEST_PRINTF_NOWARN ( " %hhu " , " unsigned char " , " unsigned char " ) ;
TEST_PRINTF_WARN ( " %hhu " , " unsigned char " , " signed short " ) ;
TEST_PRINTF_WARN ( " %hhu " , " unsigned char " , " unsigned short " ) ;
TEST_PRINTF_WARN ( " %hhu " , " unsigned char " , " signed int " ) ;
TEST_PRINTF_WARN ( " %hhu " , " unsigned char " , " unsigned int " ) ;
TEST_PRINTF_WARN ( " %hhu " , " unsigned char " , " signed long " ) ;
TEST_PRINTF_WARN ( " %hhu " , " unsigned char " , " unsigned long " ) ;
TEST_PRINTF_WARN ( " %hhu " , " unsigned char " , " signed long long " ) ;
TEST_PRINTF_WARN ( " %hhu " , " unsigned char " , " unsigned long long " ) ;
TEST_PRINTF_WARN ( " %hhu " , " unsigned char " , " float " ) ;
TEST_PRINTF_WARN ( " %hhu " , " unsigned char " , " double " ) ;
TEST_PRINTF_WARN ( " %hhu " , " unsigned char " , " long double " ) ;
TEST_PRINTF_WARN ( " %hhu " , " unsigned char " , " void * " ) ;
TEST_PRINTF_WARN_AKA ( " %hhu " , " unsigned char " , " size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %hhu " , " unsigned char " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %hhu " , " unsigned char " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %hhu " , " unsigned char " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %hhu " , " unsigned char " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %hhu " , " unsigned char " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_PRINTF_WARN_AKA_CPP ( " %hhu " , " unsigned char " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %hhu " , " unsigned char " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %hhu " , " unsigned char " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %hhu " , " unsigned char " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %hhu " , " unsigned char " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-10 21:53:53 +01:00
TEST_PRINTF_WARN ( " %hhx " , " unsigned char " , " bool " ) ;
2017-11-21 20:14:48 +01:00
TEST_PRINTF_WARN ( " %hhx " , " unsigned char " , " char " ) ;
TEST_PRINTF_WARN ( " %hhx " , " unsigned char " , " signed char " ) ;
2017-11-10 21:53:53 +01:00
TEST_PRINTF_NOWARN ( " %hhx " , " unsigned char " , " unsigned char " ) ;
TEST_PRINTF_WARN ( " %hhx " , " unsigned char " , " signed short " ) ;
TEST_PRINTF_WARN ( " %hhx " , " unsigned char " , " unsigned short " ) ;
TEST_PRINTF_WARN ( " %hhx " , " unsigned char " , " signed int " ) ;
TEST_PRINTF_WARN ( " %hhx " , " unsigned char " , " unsigned int " ) ;
TEST_PRINTF_WARN ( " %hhx " , " unsigned char " , " signed long " ) ;
TEST_PRINTF_WARN ( " %hhx " , " unsigned char " , " unsigned long " ) ;
TEST_PRINTF_WARN ( " %hhx " , " unsigned char " , " signed long long " ) ;
TEST_PRINTF_WARN ( " %hhx " , " unsigned char " , " unsigned long long " ) ;
TEST_PRINTF_WARN ( " %hhx " , " unsigned char " , " float " ) ;
TEST_PRINTF_WARN ( " %hhx " , " unsigned char " , " double " ) ;
TEST_PRINTF_WARN ( " %hhx " , " unsigned char " , " long double " ) ;
TEST_PRINTF_WARN ( " %hhx " , " unsigned char " , " void * " ) ;
TEST_PRINTF_WARN_AKA ( " %hhx " , " unsigned char " , " size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %hhx " , " unsigned char " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %hhx " , " unsigned char " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %hhx " , " unsigned char " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %hhx " , " unsigned char " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %hhx " , " unsigned char " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_PRINTF_WARN_AKA_CPP ( " %hhx " , " unsigned char " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %hhx " , " unsigned char " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %hhx " , " unsigned char " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %hhx " , " unsigned char " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %hhx " , " unsigned char " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-10 21:53:53 +01:00
TEST_PRINTF_WARN ( " %Lu " , " unsigned long long " , " bool " ) ;
TEST_PRINTF_WARN ( " %Lu " , " unsigned long long " , " char " ) ;
TEST_PRINTF_WARN ( " %Lu " , " unsigned long long " , " signed char " ) ;
TEST_PRINTF_WARN ( " %Lu " , " unsigned long long " , " unsigned char " ) ;
TEST_PRINTF_WARN ( " %Lu " , " unsigned long long " , " signed short " ) ;
TEST_PRINTF_WARN ( " %Lu " , " unsigned long long " , " unsigned short " ) ;
TEST_PRINTF_WARN ( " %Lu " , " unsigned long long " , " signed int " ) ;
TEST_PRINTF_WARN ( " %Lu " , " unsigned long long " , " unsigned int " ) ;
TEST_PRINTF_WARN ( " %Lu " , " unsigned long long " , " signed long " ) ;
TEST_PRINTF_WARN ( " %Lu " , " unsigned long long " , " unsigned long " ) ;
TEST_PRINTF_WARN ( " %Lu " , " unsigned long long " , " signed long long " ) ;
TEST_PRINTF_NOWARN ( " %Lu " , " unsigned long long " , " unsigned long long " ) ;
TEST_PRINTF_WARN ( " %Lu " , " unsigned long long " , " float " ) ;
TEST_PRINTF_WARN ( " %Lu " , " unsigned long long " , " double " ) ;
TEST_PRINTF_WARN ( " %Lu " , " unsigned long long " , " long double " ) ;
TEST_PRINTF_WARN ( " %Lu " , " unsigned long long " , " void * " ) ;
TEST_PRINTF_WARN_AKA_WIN32 ( " %Lu " , " unsigned long long " , " size_t " , " unsigned long " ) ;
TEST_PRINTF_WARN_AKA ( " %Lu " , " unsigned long long " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %Lu " , " unsigned long long " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_WIN32 ( " %Lu " , " unsigned long long " , " unsigned ptrdiff_t " , " unsigned long " ) ;
TEST_PRINTF_WARN_AKA ( " %Lu " , " unsigned long long " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_WIN32 ( " %Lu " , " unsigned long long " , " uintmax_t " , " unsigned long " ) ;
TEST_PRINTF_WARN_AKA ( " %Lu " , " unsigned long long " , " intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_WIN32 ( " %Lu " , " unsigned long long " , " uintptr_t " , " unsigned long " ) ;
2023-02-23 22:53:39 +01:00
TEST_PRINTF_WARN_AKA_CPP_WIN32 ( " %Lu " , " unsigned long long " , " std::size_t " , " unsigned long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %Lu " , " unsigned long long " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %Lu " , " unsigned long long " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %Lu " , " unsigned long long " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP_WIN32 ( " %Lu " , " unsigned long long " , " std::uintmax_t " , " unsigned long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %Lu " , " unsigned long long " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP_WIN32 ( " %Lu " , " unsigned long long " , " std::uintptr_t " , " unsigned long " ) ;
2017-11-10 21:53:53 +01:00
//TODO TEST_PRINTF_WARN("%Lx", "unsigned long long", "bool");
//TODO TEST_PRINTF_WARN("%Lx", "unsigned long long", "char");
//TODO TEST_PRINTF_WARN("%Lx", "unsigned long long", "signed char");
//TODO TEST_PRINTF_WARN("%Lx", "unsigned long long", "unsigned char");
//TODO TEST_PRINTF_WARN("%Lx", "unsigned long long", "signed short");
//TODO TEST_PRINTF_WARN("%Lx", "unsigned long long", "unsigned short");
//TODO TEST_PRINTF_WARN("%Lx", "unsigned long long", "signed int");
//TODO TEST_PRINTF_WARN("%Lx", "unsigned long long", "unsigned int");
TEST_PRINTF_WARN ( " %Lx " , " unsigned long long " , " signed long " ) ;
TEST_PRINTF_WARN ( " %Lx " , " unsigned long long " , " unsigned long " ) ;
TEST_PRINTF_WARN ( " %Lx " , " unsigned long long " , " signed long long " ) ;
//TODO TEST_PRINTF_NOWARN("%Lx", "unsigned long long", "unsigned long long");
TEST_PRINTF_WARN ( " %Lx " , " unsigned long long " , " float " ) ;
TEST_PRINTF_WARN ( " %Lx " , " unsigned long long " , " double " ) ;
TEST_PRINTF_WARN ( " %Lx " , " unsigned long long " , " long double " ) ;
TEST_PRINTF_WARN ( " %Lx " , " unsigned long long " , " void * " ) ;
TEST_PRINTF_WARN_AKA ( " %Lx " , " unsigned long long " , " size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %Lx " , " unsigned long long " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %Lx " , " unsigned long long " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %Lx " , " unsigned long long " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %Lx " , " unsigned long long " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %Lx " , " unsigned long long " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %Lx " , " unsigned long long " , " intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %Lx " , " unsigned long long " , " uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_PRINTF_WARN_AKA_CPP ( " %Lx " , " unsigned long long " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %Lx " , " unsigned long long " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %Lx " , " unsigned long long " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %Lx " , " unsigned long long " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %Lx " , " unsigned long long " , " std::uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %Lx " , " unsigned long long " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %Lx " , " unsigned long long " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-13 19:46:26 +01:00
TEST_PRINTF_WARN ( " %ju " , " uintmax_t " , " bool " ) ;
TEST_PRINTF_WARN ( " %ju " , " uintmax_t " , " char " ) ;
TEST_PRINTF_WARN ( " %ju " , " uintmax_t " , " signed char " ) ;
TEST_PRINTF_WARN ( " %ju " , " uintmax_t " , " unsigned char " ) ;
TEST_PRINTF_WARN ( " %ju " , " uintmax_t " , " signed short " ) ;
TEST_PRINTF_WARN ( " %ju " , " uintmax_t " , " unsigned short " ) ;
TEST_PRINTF_WARN ( " %ju " , " uintmax_t " , " signed int " ) ;
TEST_PRINTF_WARN ( " %ju " , " uintmax_t " , " unsigned int " ) ;
TEST_PRINTF_WARN ( " %ju " , " uintmax_t " , " signed long " ) ;
TEST_PRINTF_WARN ( " %ju " , " uintmax_t " , " unsigned long " ) ;
TEST_PRINTF_WARN ( " %ju " , " uintmax_t " , " signed long long " ) ;
TEST_PRINTF_WARN ( " %ju " , " uintmax_t " , " unsigned long long " ) ;
TEST_PRINTF_WARN ( " %ju " , " uintmax_t " , " float " ) ;
TEST_PRINTF_WARN ( " %ju " , " uintmax_t " , " double " ) ;
TEST_PRINTF_WARN ( " %ju " , " uintmax_t " , " long double " ) ;
TEST_PRINTF_WARN ( " %ju " , " uintmax_t " , " void * " ) ;
TEST_PRINTF_WARN_AKA ( " %ju " , " uintmax_t " , " size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %ju " , " uintmax_t " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %ju " , " uintmax_t " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %ju " , " uintmax_t " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %ju " , " uintmax_t " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_NOWARN ( " %ju " , " uintmax_t " , " uintmax_t " ) ;
2023-02-23 22:53:39 +01:00
TEST_PRINTF_WARN_AKA_CPP ( " %ju " , " uintmax_t " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %ju " , " uintmax_t " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %ju " , " uintmax_t " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %ju " , " uintmax_t " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %ju " , " uintmax_t " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-13 19:46:26 +01:00
TEST_PRINTF_WARN ( " %jx " , " uintmax_t " , " bool " ) ;
TEST_PRINTF_WARN ( " %jx " , " uintmax_t " , " char " ) ;
TEST_PRINTF_WARN ( " %jx " , " uintmax_t " , " signed char " ) ;
TEST_PRINTF_WARN ( " %jx " , " uintmax_t " , " unsigned char " ) ;
TEST_PRINTF_WARN ( " %jx " , " uintmax_t " , " signed short " ) ;
TEST_PRINTF_WARN ( " %jx " , " uintmax_t " , " unsigned short " ) ;
TEST_PRINTF_WARN ( " %jx " , " uintmax_t " , " signed int " ) ;
TEST_PRINTF_WARN ( " %jx " , " uintmax_t " , " unsigned int " ) ;
TEST_PRINTF_WARN ( " %jx " , " uintmax_t " , " signed long " ) ;
TEST_PRINTF_WARN ( " %jx " , " uintmax_t " , " unsigned long " ) ;
TEST_PRINTF_WARN ( " %jx " , " uintmax_t " , " signed long long " ) ;
TEST_PRINTF_WARN ( " %jx " , " uintmax_t " , " unsigned long long " ) ;
TEST_PRINTF_WARN ( " %jx " , " uintmax_t " , " float " ) ;
TEST_PRINTF_WARN ( " %jx " , " uintmax_t " , " double " ) ;
TEST_PRINTF_WARN ( " %jx " , " uintmax_t " , " long double " ) ;
TEST_PRINTF_WARN ( " %jx " , " uintmax_t " , " void * " ) ;
TEST_PRINTF_WARN_AKA ( " %jx " , " uintmax_t " , " size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %jx " , " uintmax_t " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %jx " , " uintmax_t " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %jx " , " uintmax_t " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-17 22:00:02 +01:00
TEST_PRINTF_WARN_AKA ( " %jx " , " uintmax_t " , " intmax_t " , " signed long " , " signed long long " ) ;
2017-11-13 19:46:26 +01:00
TEST_PRINTF_NOWARN ( " %jx " , " uintmax_t " , " uintmax_t " ) ;
2023-02-23 22:53:39 +01:00
TEST_PRINTF_WARN_AKA_CPP ( " %jx " , " uintmax_t " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %jx " , " uintmax_t " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %jx " , " uintmax_t " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %jx " , " uintmax_t " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %jx " , " uintmax_t " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-13 19:46:26 +01:00
2021-09-05 07:34:22 +02:00
TEST_PRINTF_WARN_AKA ( " %zd " , " ssize_t " , " size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %zi " , " ssize_t " , " size_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-13 19:46:26 +01:00
TEST_PRINTF_WARN ( " %zu " , " size_t " , " bool " ) ;
TEST_PRINTF_WARN ( " %zu " , " size_t " , " char " ) ;
TEST_PRINTF_WARN ( " %zu " , " size_t " , " signed char " ) ;
TEST_PRINTF_WARN ( " %zu " , " size_t " , " unsigned char " ) ;
TEST_PRINTF_WARN ( " %zu " , " size_t " , " signed short " ) ;
TEST_PRINTF_WARN ( " %zu " , " size_t " , " unsigned short " ) ;
TEST_PRINTF_WARN ( " %zu " , " size_t " , " signed int " ) ;
TEST_PRINTF_WARN ( " %zu " , " size_t " , " unsigned int " ) ;
TEST_PRINTF_WARN ( " %zu " , " size_t " , " signed long " ) ;
TEST_PRINTF_WARN ( " %zu " , " size_t " , " unsigned long " ) ;
TEST_PRINTF_WARN ( " %zu " , " size_t " , " signed long long " ) ;
TEST_PRINTF_WARN ( " %zu " , " size_t " , " unsigned long long " ) ;
TEST_PRINTF_WARN ( " %zu " , " size_t " , " float " ) ;
TEST_PRINTF_WARN ( " %zu " , " size_t " , " double " ) ;
TEST_PRINTF_WARN ( " %zu " , " size_t " , " long double " ) ;
TEST_PRINTF_WARN ( " %zu " , " size_t " , " void * " ) ;
TEST_PRINTF_NOWARN ( " %zu " , " size_t " , " size_t " ) ;
TEST_PRINTF_WARN_AKA ( " %zu " , " size_t " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %zu " , " size_t " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %zu " , " size_t " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %zu " , " size_t " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %zu " , " size_t " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_PRINTF_NOWARN_CPP ( " %zu " , " size_t " , " std::size_t " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %zu " , " size_t " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %zu " , " size_t " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %zu " , " size_t " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %zu " , " size_t " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-13 19:46:26 +01:00
TEST_PRINTF_WARN ( " %zx " , " size_t " , " bool " ) ;
TEST_PRINTF_WARN ( " %zx " , " size_t " , " char " ) ;
TEST_PRINTF_WARN ( " %zx " , " size_t " , " signed char " ) ;
TEST_PRINTF_WARN ( " %zx " , " size_t " , " unsigned char " ) ;
TEST_PRINTF_WARN ( " %zx " , " size_t " , " signed short " ) ;
TEST_PRINTF_WARN ( " %zx " , " size_t " , " unsigned short " ) ;
TEST_PRINTF_WARN ( " %zx " , " size_t " , " signed int " ) ;
TEST_PRINTF_WARN ( " %zx " , " size_t " , " unsigned int " ) ;
TEST_PRINTF_WARN ( " %zx " , " size_t " , " signed long " ) ;
TEST_PRINTF_WARN ( " %zx " , " size_t " , " unsigned long " ) ;
TEST_PRINTF_WARN ( " %zx " , " size_t " , " signed long long " ) ;
TEST_PRINTF_WARN ( " %zx " , " size_t " , " unsigned long long " ) ;
TEST_PRINTF_WARN ( " %zx " , " size_t " , " float " ) ;
TEST_PRINTF_WARN ( " %zx " , " size_t " , " double " ) ;
TEST_PRINTF_WARN ( " %zx " , " size_t " , " long double " ) ;
TEST_PRINTF_WARN ( " %zx " , " size_t " , " void * " ) ;
TEST_PRINTF_NOWARN ( " %zx " , " size_t " , " size_t " ) ;
TEST_PRINTF_WARN_AKA ( " %zx " , " size_t " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %zx " , " size_t " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %zx " , " size_t " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %zx " , " size_t " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %zx " , " size_t " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_PRINTF_NOWARN_CPP ( " %zx " , " size_t " , " std::size_t " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %zx " , " size_t " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %zx " , " size_t " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %zx " , " size_t " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %zx " , " size_t " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-13 19:46:26 +01:00
2017-11-15 20:40:16 +01:00
TEST_PRINTF_WARN ( " %tu " , " unsigned ptrdiff_t " , " bool " ) ;
2017-11-13 19:46:26 +01:00
TEST_PRINTF_WARN ( " %tu " , " unsigned ptrdiff_t " , " char " ) ;
TEST_PRINTF_WARN ( " %tu " , " unsigned ptrdiff_t " , " signed char " ) ;
2017-11-15 20:40:16 +01:00
TEST_PRINTF_WARN ( " %tu " , " unsigned ptrdiff_t " , " unsigned char " ) ;
2017-11-13 19:46:26 +01:00
TEST_PRINTF_WARN ( " %tu " , " unsigned ptrdiff_t " , " signed short " ) ;
2017-11-15 20:40:16 +01:00
TEST_PRINTF_WARN ( " %tu " , " unsigned ptrdiff_t " , " unsigned short " ) ;
2017-11-13 19:46:26 +01:00
TEST_PRINTF_WARN ( " %tu " , " unsigned ptrdiff_t " , " signed int " ) ;
2017-11-15 20:40:16 +01:00
TEST_PRINTF_WARN ( " %tu " , " unsigned ptrdiff_t " , " unsigned int " ) ;
2017-11-13 19:46:26 +01:00
TEST_PRINTF_WARN ( " %tu " , " unsigned ptrdiff_t " , " signed long " ) ;
TEST_PRINTF_WARN ( " %tu " , " unsigned ptrdiff_t " , " unsigned long " ) ;
TEST_PRINTF_WARN ( " %tu " , " unsigned ptrdiff_t " , " signed long long " ) ;
TEST_PRINTF_WARN ( " %tu " , " unsigned ptrdiff_t " , " unsigned long long " ) ;
TEST_PRINTF_WARN ( " %tu " , " unsigned ptrdiff_t " , " float " ) ;
TEST_PRINTF_WARN ( " %tu " , " unsigned ptrdiff_t " , " double " ) ;
TEST_PRINTF_WARN ( " %tu " , " unsigned ptrdiff_t " , " long double " ) ;
TEST_PRINTF_WARN ( " %tu " , " unsigned ptrdiff_t " , " void * " ) ;
TEST_PRINTF_WARN_AKA ( " %tu " , " unsigned ptrdiff_t " , " size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %tu " , " unsigned ptrdiff_t " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %tu " , " unsigned ptrdiff_t " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_NOWARN ( " %tu " , " unsigned ptrdiff_t " , " unsigned ptrdiff_t " ) ;
TEST_PRINTF_WARN_AKA ( " %tu " , " unsigned ptrdiff_t " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %tu " , " unsigned ptrdiff_t " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_PRINTF_WARN_AKA_CPP ( " %tu " , " unsigned ptrdiff_t " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %tu " , " unsigned ptrdiff_t " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %tu " , " unsigned ptrdiff_t " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %tu " , " unsigned ptrdiff_t " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %tu " , " unsigned ptrdiff_t " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-13 19:46:26 +01:00
TEST_PRINTF_WARN ( " %tx " , " unsigned ptrdiff_t " , " bool " ) ;
TEST_PRINTF_WARN ( " %tx " , " unsigned ptrdiff_t " , " char " ) ;
TEST_PRINTF_WARN ( " %tx " , " unsigned ptrdiff_t " , " signed char " ) ;
TEST_PRINTF_WARN ( " %tx " , " unsigned ptrdiff_t " , " unsigned char " ) ;
TEST_PRINTF_WARN ( " %tx " , " unsigned ptrdiff_t " , " signed short " ) ;
TEST_PRINTF_WARN ( " %tx " , " unsigned ptrdiff_t " , " unsigned short " ) ;
TEST_PRINTF_WARN ( " %tx " , " unsigned ptrdiff_t " , " signed int " ) ;
TEST_PRINTF_WARN ( " %tx " , " unsigned ptrdiff_t " , " unsigned int " ) ;
TEST_PRINTF_WARN ( " %tx " , " unsigned ptrdiff_t " , " signed long " ) ;
TEST_PRINTF_WARN ( " %tx " , " unsigned ptrdiff_t " , " unsigned long " ) ;
TEST_PRINTF_WARN ( " %tx " , " unsigned ptrdiff_t " , " signed long long " ) ;
TEST_PRINTF_WARN ( " %tx " , " unsigned ptrdiff_t " , " unsigned long long " ) ;
TEST_PRINTF_WARN ( " %tx " , " unsigned ptrdiff_t " , " float " ) ;
TEST_PRINTF_WARN ( " %tx " , " unsigned ptrdiff_t " , " double " ) ;
TEST_PRINTF_WARN ( " %tx " , " unsigned ptrdiff_t " , " long double " ) ;
TEST_PRINTF_WARN ( " %tx " , " unsigned ptrdiff_t " , " void * " ) ;
TEST_PRINTF_WARN_AKA ( " %tx " , " unsigned ptrdiff_t " , " size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %tx " , " unsigned ptrdiff_t " , " ssize_t " , " signed long " , " signed long long " ) ;
//TODO TEST_PRINTF_WARN_AKA("%tx", "unsigned ptrdiff_t", "ptrdiff_t", "signed long", "signed long long");
TEST_PRINTF_NOWARN ( " %tx " , " unsigned ptrdiff_t " , " unsigned ptrdiff_t " ) ;
TEST_PRINTF_WARN_AKA ( " %tx " , " unsigned ptrdiff_t " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %tx " , " unsigned ptrdiff_t " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_PRINTF_WARN_AKA_CPP ( " %tx " , " unsigned ptrdiff_t " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %tx " , " unsigned ptrdiff_t " , " std::ssize_t " , " signed long " , " signed long long " ) ;
//TODO TEST_PRINTF_WARN_AKA_CPP("%tx", "unsigned ptrdiff_t", "std::ptrdiff_t", "signed long", "signed long long");
TEST_PRINTF_WARN_AKA_CPP ( " %tx " , " unsigned ptrdiff_t " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %tx " , " unsigned ptrdiff_t " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-13 19:46:26 +01:00
TEST_PRINTF_WARN ( " %Iu " , " size_t " , " bool " ) ;
TEST_PRINTF_WARN ( " %Iu " , " size_t " , " char " ) ;
TEST_PRINTF_WARN ( " %Iu " , " size_t " , " signed char " ) ;
TEST_PRINTF_WARN ( " %Iu " , " size_t " , " unsigned char " ) ;
TEST_PRINTF_WARN ( " %Iu " , " size_t " , " signed short " ) ;
TEST_PRINTF_WARN ( " %Iu " , " size_t " , " unsigned short " ) ;
TEST_PRINTF_WARN ( " %Iu " , " size_t " , " signed int " ) ;
TEST_PRINTF_WARN ( " %Iu " , " size_t " , " unsigned int " ) ;
TEST_PRINTF_WARN ( " %Iu " , " size_t " , " signed long " ) ;
TEST_PRINTF_WARN ( " %Iu " , " size_t " , " unsigned long " ) ;
TEST_PRINTF_WARN ( " %Iu " , " size_t " , " signed long long " ) ;
TEST_PRINTF_WARN ( " %Iu " , " size_t " , " unsigned long long " ) ;
TEST_PRINTF_WARN ( " %Iu " , " size_t " , " float " ) ;
TEST_PRINTF_WARN ( " %Iu " , " size_t " , " double " ) ;
TEST_PRINTF_WARN ( " %Iu " , " size_t " , " long double " ) ;
TEST_PRINTF_WARN ( " %Iu " , " size_t " , " void * " ) ;
TEST_PRINTF_NOWARN ( " %Iu " , " size_t " , " size_t " ) ;
TEST_PRINTF_WARN_AKA ( " %Iu " , " size_t " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %Iu " , " size_t " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %Iu " , " size_t " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %Iu " , " size_t " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %Iu " , " size_t " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %Iu " , " size_t " , " intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %Iu " , " size_t " , " uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_PRINTF_NOWARN_CPP ( " %Iu " , " size_t " , " std::size_t " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %Iu " , " size_t " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %Iu " , " size_t " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %Iu " , " size_t " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %Iu " , " size_t " , " std::uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %Iu " , " size_t " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %Iu " , " size_t " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-13 19:46:26 +01:00
TEST_PRINTF_WARN ( " %Ix " , " size_t " , " bool " ) ;
TEST_PRINTF_WARN ( " %Ix " , " size_t " , " char " ) ;
TEST_PRINTF_WARN ( " %Ix " , " size_t " , " signed char " ) ;
TEST_PRINTF_WARN ( " %Ix " , " size_t " , " unsigned char " ) ;
TEST_PRINTF_WARN ( " %Ix " , " size_t " , " signed short " ) ;
TEST_PRINTF_WARN ( " %Ix " , " size_t " , " unsigned short " ) ;
TEST_PRINTF_WARN ( " %Ix " , " size_t " , " signed int " ) ;
TEST_PRINTF_WARN ( " %Ix " , " size_t " , " unsigned int " ) ;
TEST_PRINTF_WARN ( " %Ix " , " size_t " , " signed long " ) ;
TEST_PRINTF_WARN ( " %Ix " , " size_t " , " unsigned long " ) ;
TEST_PRINTF_WARN ( " %Ix " , " size_t " , " signed long long " ) ;
TEST_PRINTF_WARN ( " %Ix " , " size_t " , " unsigned long long " ) ;
TEST_PRINTF_WARN ( " %Ix " , " size_t " , " float " ) ;
TEST_PRINTF_WARN ( " %Ix " , " size_t " , " double " ) ;
TEST_PRINTF_WARN ( " %Ix " , " size_t " , " long double " ) ;
TEST_PRINTF_WARN ( " %Ix " , " size_t " , " void * " ) ;
TEST_PRINTF_NOWARN ( " %Ix " , " size_t " , " size_t " ) ;
TEST_PRINTF_WARN_AKA ( " %Ix " , " size_t " , " ssize_t " , " signed long " , " signed long long " ) ;
2017-11-20 20:51:10 +01:00
TEST_PRINTF_WARN_AKA ( " %Ix " , " size_t " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %Ix " , " size_t " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-13 19:46:26 +01:00
TEST_PRINTF_WARN_AKA ( " %Ix " , " size_t " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %Ix " , " size_t " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %Ix " , " size_t " , " intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %Ix " , " size_t " , " uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_PRINTF_NOWARN_CPP ( " %Ix " , " size_t " , " std::size_t " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %Ix " , " size_t " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %Ix " , " size_t " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %Ix " , " size_t " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %Ix " , " size_t " , " std::uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %Ix " , " size_t " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %Ix " , " size_t " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-13 19:46:26 +01:00
TEST_PRINTF_WARN ( " %I64u " , " unsigned __int64 " , " bool " ) ;
TEST_PRINTF_WARN ( " %I64u " , " unsigned __int64 " , " char " ) ;
TEST_PRINTF_WARN ( " %I64u " , " unsigned __int64 " , " signed char " ) ;
TEST_PRINTF_WARN ( " %I64u " , " unsigned __int64 " , " unsigned char " ) ;
TEST_PRINTF_WARN ( " %I64u " , " unsigned __int64 " , " signed short " ) ;
TEST_PRINTF_WARN ( " %I64u " , " unsigned __int64 " , " unsigned short " ) ;
TEST_PRINTF_WARN ( " %I64u " , " unsigned __int64 " , " signed int " ) ;
TEST_PRINTF_WARN ( " %I64u " , " unsigned __int64 " , " unsigned int " ) ;
TEST_PRINTF_WARN ( " %I64u " , " unsigned __int64 " , " signed long " ) ;
TEST_PRINTF_WARN ( " %I64u " , " unsigned __int64 " , " unsigned long " ) ;
TEST_PRINTF_WARN ( " %I64u " , " unsigned __int64 " , " signed long long " ) ;
TEST_PRINTF_NOWARN ( " %I64u " , " unsigned __int64 " , " unsigned long long " ) ;
TEST_PRINTF_WARN ( " %I64u " , " unsigned __int64 " , " float " ) ;
TEST_PRINTF_WARN ( " %I64u " , " unsigned __int64 " , " double " ) ;
TEST_PRINTF_WARN ( " %I64u " , " unsigned __int64 " , " long double " ) ;
TEST_PRINTF_WARN ( " %I64u " , " unsigned __int64 " , " void * " ) ;
TEST_PRINTF_WARN_AKA_WIN32 ( " %I64u " , " unsigned __int64 " , " size_t " , " unsigned long " ) ;
TEST_PRINTF_WARN_AKA ( " %I64u " , " unsigned __int64 " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %I64u " , " unsigned __int64 " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_WIN32 ( " %I64u " , " unsigned __int64 " , " unsigned ptrdiff_t " , " unsigned long " ) ;
TEST_PRINTF_WARN_AKA ( " %I64u " , " unsigned __int64 " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_WIN32 ( " %I64u " , " unsigned __int64 " , " uintmax_t " , " unsigned long " ) ;
TEST_PRINTF_WARN_AKA ( " %I64u " , " unsigned __int64 " , " intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_WIN32 ( " %I64u " , " unsigned __int64 " , " uintptr_t " , " unsigned long " ) ;
2023-02-23 22:53:39 +01:00
TEST_PRINTF_WARN_AKA_CPP_WIN32 ( " %I64u " , " unsigned __int64 " , " std::size_t " , " unsigned long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %I64u " , " unsigned __int64 " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %I64u " , " unsigned __int64 " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %I64u " , " unsigned __int64 " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP_WIN32 ( " %I64u " , " unsigned __int64 " , " std::uintmax_t " , " unsigned long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %I64u " , " unsigned __int64 " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP_WIN32 ( " %I64u " , " unsigned __int64 " , " std::uintptr_t " , " unsigned long " ) ;
2017-11-13 19:46:26 +01:00
TEST_PRINTF_WARN ( " %I64x " , " unsigned __int64 " , " bool " ) ;
TEST_PRINTF_WARN ( " %I64x " , " unsigned __int64 " , " char " ) ;
TEST_PRINTF_WARN ( " %I64x " , " unsigned __int64 " , " signed char " ) ;
TEST_PRINTF_WARN ( " %I64x " , " unsigned __int64 " , " unsigned char " ) ;
TEST_PRINTF_WARN ( " %I64x " , " unsigned __int64 " , " signed short " ) ;
TEST_PRINTF_WARN ( " %I64x " , " unsigned __int64 " , " unsigned short " ) ;
TEST_PRINTF_WARN ( " %I64x " , " unsigned __int64 " , " signed int " ) ;
TEST_PRINTF_WARN ( " %I64x " , " unsigned __int64 " , " unsigned int " ) ;
TEST_PRINTF_WARN ( " %I64x " , " unsigned __int64 " , " signed long " ) ;
TEST_PRINTF_WARN ( " %I64x " , " unsigned __int64 " , " unsigned long " ) ;
//TODO TEST_PRINTF_WARN("%I64x", "unsigned __int64", "signed long long");
TEST_PRINTF_NOWARN ( " %I64x " , " unsigned __int64 " , " unsigned long long " ) ;
TEST_PRINTF_WARN ( " %I64x " , " unsigned __int64 " , " float " ) ;
TEST_PRINTF_WARN ( " %I64x " , " unsigned __int64 " , " double " ) ;
TEST_PRINTF_WARN ( " %I64x " , " unsigned __int64 " , " long double " ) ;
TEST_PRINTF_WARN ( " %I64x " , " unsigned __int64 " , " void * " ) ;
//TODO TEST_PRINTF_WARN("%I64x", "unsigned __int64", "size_t");
TEST_PRINTF_WARN_AKA_WIN32 ( " %I64x " , " unsigned __int64 " , " ssize_t " , " signed long " ) ;
TEST_PRINTF_WARN_AKA_WIN32 ( " %I64x " , " unsigned __int64 " , " ptrdiff_t " , " signed long " ) ;
//TODO TEST_PRINTF_NOWARN("%I64x", "unsigned __int64", "unsigned __int64");
// TODO TEST_PRINTF_WARN("%I64x", "unsigned __int64", "__int64");
TEST_PRINTF_WARN_AKA_WIN32 ( " %I64x " , " unsigned __int64 " , " unsigned ptrdiff_t " , " unsigned long " ) ;
TEST_PRINTF_WARN_AKA_WIN32 ( " %I64x " , " unsigned __int64 " , " intmax_t " , " signed long " ) ;
TEST_PRINTF_WARN_AKA_WIN32 ( " %I64x " , " unsigned __int64 " , " uintmax_t " , " unsigned long " ) ;
TEST_PRINTF_WARN_AKA_WIN32 ( " %I64x " , " unsigned __int64 " , " intptr_t " , " signed long " ) ;
TEST_PRINTF_WARN_AKA_WIN32 ( " %I64x " , " unsigned __int64 " , " uintptr_t " , " unsigned long " ) ;
2023-02-23 22:53:39 +01:00
TEST_PRINTF_WARN_AKA_CPP_WIN32 ( " %I64x " , " unsigned __int64 " , " std::size_t " , " unsigned long " ) ;
TEST_PRINTF_WARN_AKA_CPP_WIN32 ( " %I64x " , " unsigned __int64 " , " std::ssize_t " , " signed long " ) ;
TEST_PRINTF_WARN_AKA_CPP_WIN32 ( " %I64x " , " unsigned __int64 " , " std::ptrdiff_t " , " signed long " ) ;
TEST_PRINTF_WARN_AKA_CPP_WIN32 ( " %I64x " , " unsigned __int64 " , " std::intmax_t " , " signed long " ) ;
TEST_PRINTF_WARN_AKA_CPP_WIN32 ( " %I64x " , " unsigned __int64 " , " std::uintmax_t " , " unsigned long " ) ;
TEST_PRINTF_WARN_AKA_CPP_WIN32 ( " %I64x " , " unsigned __int64 " , " std::intptr_t " , " signed long " ) ;
TEST_PRINTF_WARN_AKA_CPP_WIN32 ( " %I64x " , " unsigned __int64 " , " std::uintptr_t " , " unsigned long " ) ;
2017-11-13 19:46:26 +01:00
TEST_PRINTF_WARN ( " %I64d " , " __int64 " , " bool " ) ;
TEST_PRINTF_WARN ( " %I64d " , " __int64 " , " signed char " ) ;
TEST_PRINTF_WARN ( " %I64d " , " __int64 " , " unsigned char " ) ;
TEST_PRINTF_WARN ( " %I64d " , " __int64 " , " void * " ) ;
// TODO TEST_PRINTF_WARN("%I64d", "__int64", "size_t");
TEST_PRINTF_WARN_AKA_WIN32 ( " %I64d " , " __int64 " , " intmax_t " , " signed long " ) ;
TEST_PRINTF_WARN_AKA_WIN32 ( " %I64d " , " __int64 " , " ssize_t " , " signed long " ) ;
TEST_PRINTF_WARN_AKA_WIN32 ( " %I64d " , " __int64 " , " ptrdiff_t " , " signed long " ) ;
TEST_PRINTF_NOWARN ( " %I64d " , " __int64 " , " __int64 " ) ;
TEST_PRINTF_WARN ( " %I32u " , " unsigned __int32 " , " bool " ) ;
TEST_PRINTF_WARN ( " %I32u " , " unsigned __int32 " , " char " ) ;
TEST_PRINTF_WARN ( " %I32u " , " unsigned __int32 " , " signed char " ) ;
TEST_PRINTF_WARN ( " %I32u " , " unsigned __int32 " , " unsigned char " ) ;
TEST_PRINTF_WARN ( " %I32u " , " unsigned __int32 " , " signed short " ) ;
TEST_PRINTF_WARN ( " %I32u " , " unsigned __int32 " , " unsigned short " ) ;
TEST_PRINTF_WARN ( " %I32u " , " unsigned __int32 " , " signed int " ) ;
TEST_PRINTF_NOWARN ( " %I32u " , " unsigned __int32 " , " unsigned int " ) ;
TEST_PRINTF_WARN ( " %I32u " , " unsigned __int32 " , " signed long " ) ;
TEST_PRINTF_WARN ( " %I32u " , " unsigned __int32 " , " unsigned long " ) ;
TEST_PRINTF_WARN ( " %I32u " , " unsigned __int32 " , " signed long long " ) ;
TEST_PRINTF_WARN ( " %I32u " , " unsigned __int32 " , " unsigned long long " ) ;
TEST_PRINTF_WARN ( " %I32u " , " unsigned __int32 " , " float " ) ;
TEST_PRINTF_WARN ( " %I32u " , " unsigned __int32 " , " double " ) ;
TEST_PRINTF_WARN ( " %I32u " , " unsigned __int32 " , " long double " ) ;
TEST_PRINTF_WARN ( " %I32u " , " unsigned __int32 " , " void * " ) ;
TEST_PRINTF_WARN_AKA ( " %I32u " , " unsigned __int32 " , " size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %I32u " , " unsigned __int32 " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %I32u " , " unsigned __int32 " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %I32u " , " unsigned __int32 " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %I32u " , " unsigned __int32 " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %I32u " , " unsigned __int32 " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %I32u " , " unsigned __int32 " , " intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %I32u " , " unsigned __int32 " , " uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_PRINTF_WARN_AKA_CPP ( " %I32u " , " unsigned __int32 " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %I32u " , " unsigned __int32 " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %I32u " , " unsigned __int32 " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %I32u " , " unsigned __int32 " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %I32u " , " unsigned __int32 " , " std::uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %I32u " , " unsigned __int32 " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %I32u " , " unsigned __int32 " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-13 19:46:26 +01:00
TEST_PRINTF_WARN ( " %I32x " , " unsigned __int32 " , " bool " ) ;
TEST_PRINTF_WARN ( " %I32x " , " unsigned __int32 " , " char " ) ;
TEST_PRINTF_WARN ( " %I32x " , " unsigned __int32 " , " signed char " ) ;
TEST_PRINTF_WARN ( " %I32x " , " unsigned __int32 " , " unsigned char " ) ;
TEST_PRINTF_WARN ( " %I32x " , " unsigned __int32 " , " signed short " ) ;
TEST_PRINTF_WARN ( " %I32x " , " unsigned __int32 " , " unsigned short " ) ;
//TODO TEST_PRINTF_WARN("%I32x", "unsigned __int32", "signed int");
TEST_PRINTF_NOWARN ( " %I32x " , " unsigned __int32 " , " unsigned int " ) ;
TEST_PRINTF_WARN ( " %I32x " , " unsigned __int32 " , " signed long " ) ;
TEST_PRINTF_WARN ( " %I32x " , " unsigned __int32 " , " unsigned long " ) ;
TEST_PRINTF_WARN ( " %I32x " , " unsigned __int32 " , " signed long long " ) ;
TEST_PRINTF_WARN ( " %I32x " , " unsigned __int32 " , " unsigned long long " ) ;
TEST_PRINTF_WARN ( " %I32x " , " unsigned __int32 " , " float " ) ;
TEST_PRINTF_WARN ( " %I32x " , " unsigned __int32 " , " double " ) ;
TEST_PRINTF_WARN ( " %I32x " , " unsigned __int32 " , " long double " ) ;
TEST_PRINTF_WARN ( " %I32x " , " unsigned __int32 " , " void * " ) ;
TEST_PRINTF_WARN_AKA ( " %I32x " , " unsigned __int32 " , " size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %I32x " , " unsigned __int32 " , " ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %I32x " , " unsigned __int32 " , " ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %I32x " , " unsigned __int32 " , " unsigned ptrdiff_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %I32x " , " unsigned __int32 " , " intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %I32x " , " unsigned __int32 " , " uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA ( " %I32x " , " unsigned __int32 " , " intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA ( " %I32x " , " unsigned __int32 " , " uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2023-02-23 22:53:39 +01:00
TEST_PRINTF_WARN_AKA_CPP ( " %I32x " , " unsigned __int32 " , " std::size_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %I32x " , " unsigned __int32 " , " std::ssize_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %I32x " , " unsigned __int32 " , " std::ptrdiff_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %I32x " , " unsigned __int32 " , " std::intmax_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %I32x " , " unsigned __int32 " , " std::uintmax_t " , " unsigned long " , " unsigned long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %I32x " , " unsigned __int32 " , " std::intptr_t " , " signed long " , " signed long long " ) ;
TEST_PRINTF_WARN_AKA_CPP ( " %I32x " , " unsigned __int32 " , " std::uintptr_t " , " unsigned long " , " unsigned long long " ) ;
2017-11-10 21:53:53 +01:00
}
2014-11-20 14:20:09 +01:00
void testPosixPrintfScanfParameterPosition ( ) { // #4900 - No support for parameters in format strings
2013-07-28 15:00:28 +02:00
check ( " void foo() { "
" int bar; "
" printf( \" %1$d \" , 1); "
" printf( \" %1$d, %d, %1$d \" , 1, 2); "
2013-07-28 16:13:16 +02:00
" scanf( \" %1$d \" , &bar); "
2013-07-28 15:00:28 +02:00
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo() { \n "
" int bar; \n "
" printf( \" %1$d \" ); \n "
" printf( \" %1$d, %d, %4$d \" , 1, 2, 3); \n "
" scanf( \" %2$d \" , &bar); \n "
" printf( \" %0$f \" , 0.0); \n "
" } " ) ;
2013-09-30 19:55:21 +02:00
ASSERT_EQUALS ( " [test.cpp:3]: (error) printf format string requires 1 parameter but only 0 are given. \n "
2013-07-28 15:00:28 +02:00
" [test.cpp:4]: (warning) printf: referencing parameter 4 while 3 arguments given \n "
" [test.cpp:5]: (warning) scanf: referencing parameter 2 while 1 arguments given \n "
" [test.cpp:6]: (warning) printf: parameter positions start at 1, not 0 \n "
" " , errout . str ( ) ) ;
}
2014-11-20 14:20:09 +01:00
void testMicrosoftPrintfArgument ( ) {
2013-07-21 08:35:01 +02:00
check ( " void foo() { \n "
" size_t s; \n "
" ptrdiff_t p; \n "
" __int32 i32; \n "
" unsigned __int32 u32; \n "
" __int64 i64; \n "
" unsigned __int64 u64; \n "
" printf( \" %Id %Iu %Ix \" , s, s, s); \n "
" printf( \" %Id %Iu %Ix \" , p, p, p); \n "
" printf( \" %I32d %I32u %I32x \" , i32, i32, i32); \n "
" printf( \" %I32d %I32u %I32x \" , u32, u32, u32); \n "
" printf( \" %I64d %I64u %I64x \" , i64, i64, i64); \n "
" printf( \" %I64d %I64u %I64x \" , u64, u64, u64); \n "
2023-03-03 18:36:27 +01:00
" } " , false , true , cppcheck : : Platform : : Type : : Win32A ) ;
2016-09-11 17:05:01 +02:00
ASSERT_EQUALS ( " [test.cpp:8]: (portability) %Id in format string (no. 1) requires 'ptrdiff_t' but the argument type is 'size_t {aka unsigned long}'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:9]: (portability) %Iu in format string (no. 2) requires 'size_t' but the argument type is 'ptrdiff_t {aka signed long}'. \n "
2017-11-20 20:51:10 +01:00
" [test.cpp:9]: (portability) %Ix in format string (no. 3) requires 'size_t' but the argument type is 'ptrdiff_t {aka signed long}'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:10]: (portability) %I32u in format string (no. 2) requires 'unsigned __int32' but the argument type is '__int32 {aka signed int}'. \n "
2016-09-11 17:05:01 +02:00
" [test.cpp:11]: (portability) %I32d in format string (no. 1) requires '__int32' but the argument type is 'unsigned __int32 {aka unsigned int}'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:12]: (portability) %I64u in format string (no. 2) requires 'unsigned __int64' but the argument type is '__int64 {aka signed long long}'. \n "
2016-09-11 17:05:01 +02:00
" [test.cpp:13]: (portability) %I64d in format string (no. 1) requires '__int64' but the argument type is 'unsigned __int64 {aka unsigned long long}'. \n " , errout . str ( ) ) ;
2013-08-31 06:26:39 +02:00
check ( " void foo() { \n "
" size_t s; \n "
" ptrdiff_t p; \n "
" __int32 i32; \n "
" unsigned __int32 u32; \n "
" __int64 i64; \n "
" unsigned __int64 u64; \n "
" printf( \" %Id %Iu %Ix \" , s, s, s); \n "
" printf( \" %Id %Iu %Ix \" , p, p, p); \n "
" printf( \" %I32d %I32u %I32x \" , i32, i32, i32); \n "
" printf( \" %I32d %I32u %I32x \" , u32, u32, u32); \n "
" printf( \" %I64d %I64u %I64x \" , i64, i64, i64); \n "
" printf( \" %I64d %I64u %I64x \" , u64, u64, u64); \n "
2023-03-03 18:36:27 +01:00
" } " , false , true , cppcheck : : Platform : : Type : : Win64 ) ;
2016-09-11 17:05:01 +02:00
ASSERT_EQUALS ( " [test.cpp:8]: (portability) %Id in format string (no. 1) requires 'ptrdiff_t' but the argument type is 'size_t {aka unsigned long long}'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:9]: (portability) %Iu in format string (no. 2) requires 'size_t' but the argument type is 'ptrdiff_t {aka signed long long}'. \n "
2017-11-20 20:51:10 +01:00
" [test.cpp:9]: (portability) %Ix in format string (no. 3) requires 'size_t' but the argument type is 'ptrdiff_t {aka signed long long}'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:10]: (portability) %I32u in format string (no. 2) requires 'unsigned __int32' but the argument type is '__int32 {aka signed int}'. \n "
2016-09-11 17:05:01 +02:00
" [test.cpp:11]: (portability) %I32d in format string (no. 1) requires '__int32' but the argument type is 'unsigned __int32 {aka unsigned int}'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:12]: (portability) %I64u in format string (no. 2) requires 'unsigned __int64' but the argument type is '__int64 {aka signed long long}'. \n "
2016-09-11 17:05:01 +02:00
" [test.cpp:13]: (portability) %I64d in format string (no. 1) requires '__int64' but the argument type is 'unsigned __int64 {aka unsigned long long}'. \n " , errout . str ( ) ) ;
2013-08-10 12:37:31 +02:00
check ( " void foo() { \n "
" size_t s; \n "
" int i; \n "
" printf( \" %I \" , s); \n "
" printf( \" %I6 \" , s); \n "
" printf( \" %I6x \" , s); \n "
" printf( \" %I16 \" , s); \n "
" printf( \" %I16x \" , s); \n "
" printf( \" %I32 \" , s); \n "
" printf( \" %I64 \" , s); \n "
" printf( \" %I%i \" , s, i); \n "
" printf( \" %I6%i \" , s, i); \n "
" printf( \" %I6x%i \" , s, i); \n "
" printf( \" %I16%i \" , s, i); \n "
" printf( \" %I16x%i \" , s, i); \n "
" printf( \" %I32%i \" , s, i); \n "
" printf( \" %I64%i \" , s, i); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:4]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:6]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:7]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:8]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:9]: (warning) 'I32' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:10]: (warning) 'I64' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:11]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:12]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:13]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:14]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:15]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:16]: (warning) 'I32' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:17]: (warning) 'I64' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n " , errout . str ( ) ) ;
2014-01-03 15:58:45 +01:00
// ticket #5264
check ( " void foo(LPARAM lp, WPARAM wp, LRESULT lr) { \n "
" printf( \" %Ix %Ix %Ix \" , lp, wp, lr); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , true , cppcheck : : Platform : : Type : : Win64 ) ;
2014-01-03 15:58:45 +01:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo(LPARAM lp, WPARAM wp, LRESULT lr) { \n "
" printf( \" %Ix %Ix %Ix \" , lp, wp, lr); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , true , cppcheck : : Platform : : Type : : Win32A ) ;
2014-01-03 15:58:45 +01:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2014-10-19 07:34:40 +02:00
check ( " void foo(UINT32 a, ::UINT32 b, Fred::UINT32 c) { \n "
2017-05-18 17:23:26 +02:00
" printf( \" %d %d %d \" , a, b, c); \n "
2023-03-03 18:36:27 +01:00
" }; \n " , false , true , cppcheck : : Platform : : Type : : Win32A ) ;
2016-09-11 17:05:01 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (portability) %d in format string (no. 1) requires 'int' but the argument type is 'UINT32 {aka unsigned int}'. \n "
" [test.cpp:2]: (portability) %d in format string (no. 2) requires 'int' but the argument type is 'UINT32 {aka unsigned int}'. \n " , errout . str ( ) ) ;
2014-10-19 07:34:40 +02:00
check ( " void foo(LPCVOID a, ::LPCVOID b, Fred::LPCVOID c) { \n "
2017-05-18 17:23:26 +02:00
" printf( \" %d %d %d \" , a, b, c); \n "
2023-03-03 18:36:27 +01:00
" }; \n " , false , true , cppcheck : : Platform : : Type : : Win32A ) ;
2014-10-19 07:34:40 +02:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'const void *'. \n "
" [test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'const void *'. \n " , errout . str ( ) ) ;
2019-10-24 21:51:20 +02:00
check ( " void foo() { \n "
" SSIZE_T s = -2; \n " // In MSVC, SSIZE_T is available in capital letters using #include <BaseTsd.h>
" int i; \n "
" printf( \" %zd \" , s); \n "
" printf( \" %zd%i \" , s, i); \n "
" printf( \" %zu \" , s); \n "
2023-03-03 18:36:27 +01:00
" } " , false , true , cppcheck : : Platform : : Type : : Win32A ) ;
2019-10-24 21:51:20 +02:00
ASSERT_EQUALS ( " [test.cpp:6]: (portability) %zu in format string (no. 1) requires 'size_t' but the argument type is 'SSIZE_T {aka signed long}'. \n " , errout . str ( ) ) ;
check ( " void foo() { \n "
" SSIZE_T s = -2; \n " // In MSVC, SSIZE_T is available in capital letters using #include <BaseTsd.h>
" int i; \n "
" printf( \" %zd \" , s); \n "
" printf( \" %zd%i \" , s, i); \n "
" printf( \" %zu \" , s); \n "
2023-03-03 18:36:27 +01:00
" } " , false , true , cppcheck : : Platform : : Type : : Win64 ) ;
2019-10-24 21:51:20 +02:00
ASSERT_EQUALS ( " [test.cpp:6]: (portability) %zu in format string (no. 1) requires 'size_t' but the argument type is 'SSIZE_T {aka signed long long}'. \n " , errout . str ( ) ) ;
check ( " void foo() { \n "
" SSIZE_T s = -2; \n " // Under Unix, ssize_t has to be written in small letters. Not Cppcheck, but the compiler will report this.
" int i; \n "
" printf( \" %zd \" , s); \n "
" printf( \" %zd%i \" , s, i); \n "
" printf( \" %zu \" , s); \n "
2023-03-03 18:36:27 +01:00
" } " , false , true , cppcheck : : Platform : : Type : : Unix64 ) ;
2019-10-24 21:51:20 +02:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo() { \n "
" typedef SSIZE_T ssize_t; \n " // Test using typedef
" ssize_t s = -2; \n "
" int i; \n "
" printf( \" %zd \" , s); \n "
" printf( \" %zd%i \" , s, i); \n "
" printf( \" %zu \" , s); \n "
2023-03-03 18:36:27 +01:00
" } " , false , true , cppcheck : : Platform : : Type : : Win64 ) ;
2019-10-24 21:51:20 +02:00
ASSERT_EQUALS ( " [test.cpp:7]: (portability) %zu in format string (no. 1) requires 'size_t' but the argument type is 'SSIZE_T {aka signed long long}'. \n " , errout . str ( ) ) ;
2013-07-21 08:35:01 +02:00
}
2013-07-22 20:21:45 +02:00
2014-11-20 14:20:09 +01:00
void testMicrosoftScanfArgument ( ) {
2013-10-03 06:37:40 +02:00
check ( " void foo() { \n "
" size_t s; \n "
" ptrdiff_t p; \n "
" __int32 i32; \n "
" unsigned __int32 u32; \n "
" __int64 i64; \n "
" unsigned __int64 u64; \n "
" scanf( \" %Id %Iu %Ix \" , &s, &s, &s); \n "
" scanf( \" %Id %Iu %Ix \" , &p, &p, &p); \n "
" scanf( \" %I32d %I32u %I32x \" , &i32, &i32, &i32); \n "
" scanf( \" %I32d %I32u %I32x \" , &u32, &u32, &u32); \n "
" scanf( \" %I64d %I64u %I64x \" , &i64, &i64, &i64); \n "
" scanf( \" %I64d %I64u %I64x \" , &u64, &u64, &u64); \n "
2023-03-03 18:36:27 +01:00
" } " , false , true , cppcheck : : Platform : : Type : : Win32A ) ;
2016-09-11 17:05:01 +02:00
ASSERT_EQUALS ( " [test.cpp:8]: (portability) %Id in format string (no. 1) requires 'ptrdiff_t *' but the argument type is 'size_t * {aka unsigned long *}'. \n "
" [test.cpp:9]: (portability) %Iu in format string (no. 2) requires 'size_t *' but the argument type is 'ptrdiff_t * {aka signed long *}'. \n "
2017-10-25 20:22:17 +02:00
" [test.cpp:9]: (portability) %Ix in format string (no. 3) requires 'size_t *' but the argument type is 'ptrdiff_t * {aka signed long *}'. \n "
2016-09-11 17:05:01 +02:00
" [test.cpp:10]: (portability) %I32u in format string (no. 2) requires 'unsigned __int32 *' but the argument type is '__int32 * {aka signed int *}'. \n "
2017-10-25 20:22:17 +02:00
" [test.cpp:10]: (portability) %I32x in format string (no. 3) requires 'unsigned __int32 *' but the argument type is '__int32 * {aka signed int *}'. \n "
2016-09-11 17:05:01 +02:00
" [test.cpp:11]: (portability) %I32d in format string (no. 1) requires '__int32 *' but the argument type is 'unsigned __int32 * {aka unsigned int *}'. \n "
" [test.cpp:12]: (portability) %I64u in format string (no. 2) requires 'unsigned __int64 *' but the argument type is '__int64 * {aka signed long long *}'. \n "
2017-10-25 20:22:17 +02:00
" [test.cpp:12]: (portability) %I64x in format string (no. 3) requires 'unsigned __int64 *' but the argument type is '__int64 * {aka signed long long *}'. \n "
2016-09-11 17:05:01 +02:00
" [test.cpp:13]: (portability) %I64d in format string (no. 1) requires '__int64 *' but the argument type is 'unsigned __int64 * {aka unsigned long long *}'. \n " , errout . str ( ) ) ;
2013-10-03 06:37:40 +02:00
check ( " void foo() { \n "
" size_t s; \n "
" ptrdiff_t p; \n "
" __int32 i32; \n "
" unsigned __int32 u32; \n "
" __int64 i64; \n "
" unsigned __int64 u64; \n "
" scanf( \" %Id %Iu %Ix \" , &s, &s, &s); \n "
" scanf( \" %Id %Iu %Ix \" , &p, &p, &p); \n "
" scanf( \" %I32d %I32u %I32x \" , &i32, &i32, &i32); \n "
" scanf( \" %I32d %I32u %I32x \" , &u32, &u32, &u32); \n "
" scanf( \" %I64d %I64u %I64x \" , &i64, &i64, &i64); \n "
" scanf( \" %I64d %I64u %I64x \" , &u64, &u64, &u64); \n "
2023-03-03 18:36:27 +01:00
" } " , false , true , cppcheck : : Platform : : Type : : Win64 ) ;
2016-09-11 17:05:01 +02:00
ASSERT_EQUALS ( " [test.cpp:8]: (portability) %Id in format string (no. 1) requires 'ptrdiff_t *' but the argument type is 'size_t * {aka unsigned long long *}'. \n "
" [test.cpp:9]: (portability) %Iu in format string (no. 2) requires 'size_t *' but the argument type is 'ptrdiff_t * {aka signed long long *}'. \n "
2017-10-25 20:22:17 +02:00
" [test.cpp:9]: (portability) %Ix in format string (no. 3) requires 'size_t *' but the argument type is 'ptrdiff_t * {aka signed long long *}'. \n "
2016-09-11 17:05:01 +02:00
" [test.cpp:10]: (portability) %I32u in format string (no. 2) requires 'unsigned __int32 *' but the argument type is '__int32 * {aka signed int *}'. \n "
2017-10-25 20:22:17 +02:00
" [test.cpp:10]: (portability) %I32x in format string (no. 3) requires 'unsigned __int32 *' but the argument type is '__int32 * {aka signed int *}'. \n "
2016-09-11 17:05:01 +02:00
" [test.cpp:11]: (portability) %I32d in format string (no. 1) requires '__int32 *' but the argument type is 'unsigned __int32 * {aka unsigned int *}'. \n "
" [test.cpp:12]: (portability) %I64u in format string (no. 2) requires 'unsigned __int64 *' but the argument type is '__int64 * {aka signed long long *}'. \n "
2017-10-25 20:22:17 +02:00
" [test.cpp:12]: (portability) %I64x in format string (no. 3) requires 'unsigned __int64 *' but the argument type is '__int64 * {aka signed long long *}'. \n "
2016-09-11 17:05:01 +02:00
" [test.cpp:13]: (portability) %I64d in format string (no. 1) requires '__int64 *' but the argument type is 'unsigned __int64 * {aka unsigned long long *}'. \n " , errout . str ( ) ) ;
2013-10-03 06:37:40 +02:00
check ( " void foo() { \n "
" size_t s; \n "
" int i; \n "
" scanf( \" %I \" , &s); \n "
" scanf( \" %I6 \" , &s); \n "
" scanf( \" %I6x \" , &s); \n "
" scanf( \" %I16 \" , &s); \n "
" scanf( \" %I16x \" , &s); \n "
" scanf( \" %I32 \" , &s); \n "
" scanf( \" %I64 \" , &s); \n "
" scanf( \" %I%i \" , &s, &i); \n "
" scanf( \" %I6%i \" , &s, &i); \n "
" scanf( \" %I6x%i \" , &s, &i); \n "
" scanf( \" %I16%i \" , &s, &i); \n "
" scanf( \" %I16x%i \" , &s, &i); \n "
" scanf( \" %I32%i \" , &s, &i); \n "
" scanf( \" %I64%i \" , &s, &i); \n "
" } " ) ;
ASSERT_EQUALS ( " [test.cpp:4]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:5]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:6]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:7]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:8]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:9]: (warning) 'I32' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:10]: (warning) 'I64' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:11]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:12]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:13]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:14]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:15]: (warning) 'I' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:16]: (warning) 'I32' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n "
" [test.cpp:17]: (warning) 'I64' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier. \n " , errout . str ( ) ) ;
2019-10-24 21:51:20 +02:00
check ( " void foo() { \n "
" SSIZE_T s; \n " // In MSVC, SSIZE_T is available in capital letters using #include <BaseTsd.h>
" int i; \n "
" scanf( \" %zd \" , &s); \n "
" scanf( \" %zd%i \" , &s, &i); \n "
" scanf( \" %zu \" , &s); \n "
2023-03-03 18:36:27 +01:00
" } " , false , true , cppcheck : : Platform : : Type : : Win32A ) ;
2019-10-24 21:51:20 +02:00
ASSERT_EQUALS ( " [test.cpp:6]: (portability) %zu in format string (no. 1) requires 'size_t *' but the argument type is 'SSIZE_T * {aka signed long *}'. \n " , errout . str ( ) ) ;
check ( " void foo() { \n "
" SSIZE_T s; \n " // In MSVC, SSIZE_T is available in capital letters using #include <BaseTsd.h>
" int i; \n "
" scanf( \" %zd \" , &s); \n "
" scanf( \" %zd%i \" , &s, &i); \n "
" scanf( \" %zu \" , &s); \n "
2023-03-03 18:36:27 +01:00
" } " , false , true , cppcheck : : Platform : : Type : : Win64 ) ;
2019-10-24 21:51:20 +02:00
ASSERT_EQUALS ( " [test.cpp:6]: (portability) %zu in format string (no. 1) requires 'size_t *' but the argument type is 'SSIZE_T * {aka signed long long *}'. \n " , errout . str ( ) ) ;
check ( " void foo() { \n "
" SSIZE_T s; \n " // Under Unix, ssize_t has to be written in small letters. Not Cppcheck, but the compiler will report this.
" int i; \n "
" scanf( \" %zd \" , &s); \n "
" scanf( \" %zd%i \" , &s, &i); \n "
" scanf( \" %zu \" , &s); \n "
2023-03-03 18:36:27 +01:00
" } " , false , true , cppcheck : : Platform : : Type : : Unix64 ) ;
2019-10-24 21:51:20 +02:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo() { \n "
" typedef SSIZE_T ssize_t; \n " // Test using typedef
" ssize_t s; \n "
" int i; \n "
" scanf( \" %zd \" , &s); \n "
" scanf( \" %zd%i \" , &s, &i); \n "
" scanf( \" %zu \" , &s); \n "
2023-03-03 18:36:27 +01:00
" } " , false , true , cppcheck : : Platform : : Type : : Win64 ) ;
2019-10-24 21:51:20 +02:00
ASSERT_EQUALS ( " [test.cpp:7]: (portability) %zu in format string (no. 1) requires 'size_t *' but the argument type is 'SSIZE_T * {aka signed long long *}'. \n " , errout . str ( ) ) ;
2013-10-03 06:37:40 +02:00
}
2014-11-20 14:20:09 +01:00
void testMicrosoftCStringFormatArguments ( ) { // ticket #4920
2013-09-26 16:20:01 +02:00
check ( " void foo() { \n "
" unsigned __int32 u32; \n "
" String string; \n "
" string.Format( \" %I32d \" , u32); \n "
" string.AppendFormat( \" %I32d \" , u32); \n "
2023-03-03 18:36:27 +01:00
" } " , false , true , cppcheck : : Platform : : Type : : Win32A ) ;
2013-09-26 16:20:01 +02:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo() { \n "
" unsigned __int32 u32; \n "
" CString string; \n "
" string.Format( \" %I32d \" , u32); \n "
" string.AppendFormat( \" %I32d \" , u32); \n "
2023-03-03 18:36:27 +01:00
" } " , false , true , cppcheck : : Platform : : Type : : Unix32 ) ;
2013-09-26 16:20:01 +02:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo() { \n "
" unsigned __int32 u32; \n "
" CString string; \n "
" string.Format( \" %I32d \" , u32); \n "
" string.AppendFormat( \" %I32d \" , u32); \n "
2016-08-19 17:36:27 +02:00
" CString::Format( \" %I32d \" , u32); \n "
2023-03-03 18:36:27 +01:00
" } " , false , true , cppcheck : : Platform : : Type : : Win32A ) ;
2016-09-11 17:05:01 +02:00
ASSERT_EQUALS ( " [test.cpp:4]: (portability) %I32d in format string (no. 1) requires '__int32' but the argument type is 'unsigned __int32 {aka unsigned int}'. \n "
" [test.cpp:5]: (portability) %I32d in format string (no. 1) requires '__int32' but the argument type is 'unsigned __int32 {aka unsigned int}'. \n "
" [test.cpp:6]: (portability) %I32d in format string (no. 1) requires '__int32' but the argument type is 'unsigned __int32 {aka unsigned int}'. \n " , errout . str ( ) ) ;
2013-09-26 16:20:01 +02:00
}
2014-11-20 14:20:09 +01:00
void testMicrosoftSecurePrintfArgument ( ) {
2013-09-30 19:55:21 +02:00
check ( " void foo() { \n "
" int i; \n "
" unsigned int u; \n "
" _tprintf_s(_T( \" %d %u \" ), u, i, 0); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32A ) ;
2013-09-30 19:55:21 +02:00
ASSERT_EQUALS ( " [test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:4]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
2013-09-30 19:55:21 +02:00
" [test.cpp:4]: (warning) _tprintf_s format string requires 2 parameters but 3 are given. \n " , errout . str ( ) ) ;
check ( " void foo() { \n "
" int i; \n "
" unsigned int u; \n "
" _tprintf_s(_T( \" %d %u \" ), u, i, 0); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2013-09-30 19:55:21 +02:00
ASSERT_EQUALS ( " [test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:4]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
2013-09-30 19:55:21 +02:00
" [test.cpp:4]: (warning) _tprintf_s format string requires 2 parameters but 3 are given. \n " , errout . str ( ) ) ;
2013-10-01 05:49:44 +02:00
check ( " void foo() { \n "
" int i; \n "
" unsigned int u; \n "
" printf_s( \" %d %u \" , u, i, 0); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32A ) ;
2013-10-01 05:49:44 +02:00
ASSERT_EQUALS ( " [test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:4]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
2013-10-01 05:49:44 +02:00
" [test.cpp:4]: (warning) printf_s format string requires 2 parameters but 3 are given. \n " , errout . str ( ) ) ;
check ( " void foo() { \n "
" int i; \n "
" unsigned int u; \n "
" wprintf_s(L \" %d %u \" , u, i, 0); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2013-10-01 05:49:44 +02:00
ASSERT_EQUALS ( " [test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:4]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
2013-10-01 05:49:44 +02:00
" [test.cpp:4]: (warning) wprintf_s format string requires 2 parameters but 3 are given. \n " , errout . str ( ) ) ;
2013-09-30 19:55:21 +02:00
check ( " void foo() { \n "
" TCHAR str[10]; \n "
" int i; \n "
" unsigned int u; \n "
" _stprintf_s(str, sizeof(str) / sizeof(TCHAR), _T( \" %d %u \" ), u, i, 0); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32A ) ;
2013-09-30 19:55:21 +02:00
ASSERT_EQUALS ( " [test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
2013-09-30 19:55:21 +02:00
" [test.cpp:5]: (warning) _stprintf_s format string requires 2 parameters but 3 are given. \n " , errout . str ( ) ) ;
check ( " void foo() { \n "
" TCHAR str[10]; \n "
" int i; \n "
" unsigned int u; \n "
" _stprintf_s(str, sizeof(str) / sizeof(TCHAR), _T( \" %d %u \" ), u, i, 0); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2013-09-30 19:55:21 +02:00
ASSERT_EQUALS ( " [test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
2013-09-30 19:55:21 +02:00
" [test.cpp:5]: (warning) _stprintf_s format string requires 2 parameters but 3 are given. \n " , errout . str ( ) ) ;
2013-10-01 05:49:44 +02:00
check ( " void foo() { \n "
" char str[10]; \n "
" int i; \n "
" unsigned int u; \n "
" sprintf_s(str, sizeof(str), \" %d %u \" , u, i, 0); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32A ) ;
2013-10-01 05:49:44 +02:00
ASSERT_EQUALS ( " [test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
2013-10-01 05:49:44 +02:00
" [test.cpp:5]: (warning) sprintf_s format string requires 2 parameters but 3 are given. \n " , errout . str ( ) ) ;
2018-02-03 05:10:52 +01:00
check ( " void foo() { \n "
" char str[10]; \n "
" int i; \n "
" unsigned int u; \n "
" sprintf_s(str, \" %d %u \" , u, i, 0); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32A ) ;
2018-02-03 05:10:52 +01:00
ASSERT_EQUALS ( " [test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. \n "
" [test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
" [test.cpp:5]: (warning) sprintf_s format string requires 2 parameters but 3 are given. \n " , errout . str ( ) ) ;
2013-10-01 05:49:44 +02:00
check ( " void foo() { \n "
" wchar_t str[10]; \n "
" int i; \n "
" unsigned int u; \n "
" swprintf_s(str, sizeof(str) / sizeof(wchar_t), L \" %d %u \" , u, i, 0); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2013-10-01 05:49:44 +02:00
ASSERT_EQUALS ( " [test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
2013-10-01 05:49:44 +02:00
" [test.cpp:5]: (warning) swprintf_s format string requires 2 parameters but 3 are given. \n " , errout . str ( ) ) ;
2018-02-03 05:10:52 +01:00
check ( " void foo() { \n "
" wchar_t str[10]; \n "
" int i; \n "
" unsigned int u; \n "
" swprintf_s(str, L \" %d %u \" , u, i, 0); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2018-02-03 05:10:52 +01:00
ASSERT_EQUALS ( " [test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. \n "
" [test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
" [test.cpp:5]: (warning) swprintf_s format string requires 2 parameters but 3 are given. \n " , errout . str ( ) ) ;
2013-09-30 19:55:21 +02:00
check ( " void foo() { \n "
" TCHAR str[10]; \n "
" int i; \n "
" unsigned int u; \n "
" _sntprintf_s(str, sizeof(str) / sizeof(TCHAR), _TRUNCATE, _T( \" %d %u \" ), u, i, 0); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32A ) ;
2013-09-30 19:55:21 +02:00
ASSERT_EQUALS ( " [test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
2013-09-30 19:55:21 +02:00
" [test.cpp:5]: (warning) _sntprintf_s format string requires 2 parameters but 3 are given. \n " , errout . str ( ) ) ;
check ( " void foo() { \n "
" TCHAR str[10]; \n "
" int i; \n "
" unsigned int u; \n "
" _sntprintf_s(str, sizeof(str) / sizeof(TCHAR), _TRUNCATE, _T( \" %d %u \" ), u, i, 0); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2013-09-30 19:55:21 +02:00
ASSERT_EQUALS ( " [test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
2013-09-30 19:55:21 +02:00
" [test.cpp:5]: (warning) _sntprintf_s format string requires 2 parameters but 3 are given. \n " , errout . str ( ) ) ;
2013-10-01 05:49:44 +02:00
check ( " void foo() { \n "
" char str[10]; \n "
" int i; \n "
" unsigned int u; \n "
" _snprintf_s(str, sizeof(str), _TRUNCATE, \" %d %u \" , u, i, 0); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32A ) ;
2013-10-01 05:49:44 +02:00
ASSERT_EQUALS ( " [test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
2013-10-01 05:49:44 +02:00
" [test.cpp:5]: (warning) _snprintf_s format string requires 2 parameters but 3 are given. \n " , errout . str ( ) ) ;
check ( " void foo() { \n "
" wchar_t str[10]; \n "
" int i; \n "
" unsigned int u; \n "
" _snwprintf_s(str, sizeof(str) / sizeof(wchar_t), _TRUNCATE, L \" %d %u \" , u, i, 0); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2013-10-01 05:49:44 +02:00
ASSERT_EQUALS ( " [test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
2013-10-01 05:49:44 +02:00
" [test.cpp:5]: (warning) _snwprintf_s format string requires 2 parameters but 3 are given. \n " , errout . str ( ) ) ;
2013-10-03 06:37:40 +02:00
check ( " void foo(FILE * fp) { \n "
" int i; \n "
" unsigned int u; \n "
" _ftprintf_s(fp, _T( \" %d %u \" ), u, i, 0); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32A ) ;
2013-10-03 06:37:40 +02:00
ASSERT_EQUALS ( " [test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:4]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
2013-10-03 06:37:40 +02:00
" [test.cpp:4]: (warning) _ftprintf_s format string requires 2 parameters but 3 are given. \n " , errout . str ( ) ) ;
check ( " void foo(FILE * fp) { \n "
" int i; \n "
" unsigned int u; \n "
" _ftprintf_s(fp, _T( \" %d %u \" ), u, i, 0); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2013-10-03 06:37:40 +02:00
ASSERT_EQUALS ( " [test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:4]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
2013-10-03 06:37:40 +02:00
" [test.cpp:4]: (warning) _ftprintf_s format string requires 2 parameters but 3 are given. \n " , errout . str ( ) ) ;
check ( " void foo(FILE * fp) { \n "
" int i; \n "
" unsigned int u; \n "
" fprintf_s(fp, \" %d %u \" , u, i, 0); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32A ) ;
2013-10-03 06:37:40 +02:00
ASSERT_EQUALS ( " [test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:4]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
2013-10-03 06:37:40 +02:00
" [test.cpp:4]: (warning) fprintf_s format string requires 2 parameters but 3 are given. \n " , errout . str ( ) ) ;
check ( " void foo(FILE * fp) { \n "
" int i; \n "
" unsigned int u; \n "
" fwprintf_s(fp, L \" %d %u \" , u, i, 0); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2013-10-03 06:37:40 +02:00
ASSERT_EQUALS ( " [test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:4]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'. \n "
2013-10-03 06:37:40 +02:00
" [test.cpp:4]: (warning) fwprintf_s format string requires 2 parameters but 3 are given. \n " , errout . str ( ) ) ;
2013-10-04 17:30:55 +02:00
check ( " void foo() { \n "
" char lineBuffer [600]; \n "
2017-05-18 17:23:26 +02:00
" const char * const format = \" %15s%17s%17s%17s%17s \" ; \n "
2016-05-18 09:31:26 +02:00
" sprintf_s(lineBuffer, 600, format, \" type \" , \" sum \" , \" avg \" , \" min \" , \" max \" ); \n "
2016-05-19 08:22:40 +02:00
" sprintf_s(lineBuffer, format, \" type \" , \" sum \" , \" avg \" , \" min \" , \" max \" ); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32A ) ;
2013-10-04 17:30:55 +02:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " void foo() { \n "
2017-05-18 17:23:26 +02:00
" const char * const format1 = \" %15s%17s%17s%17s%17s \" ; \n "
" const char format2[] = \" %15s%17s%17s%17s%17s \" ; \n "
2015-11-06 09:52:22 +01:00
" const char * const format3 = format1; \n "
2013-10-05 07:47:52 +02:00
" int i = 0; \n "
2016-05-19 08:22:40 +02:00
" sprintf_s(lineBuffer, format1, \" type \" , \" sum \" , \" avg \" , \" min \" , i, 0); \n "
" sprintf_s(lineBuffer, format2, \" type \" , \" sum \" , \" avg \" , \" min \" , i, 0); \n "
" sprintf_s(lineBuffer, format3, \" type \" , \" sum \" , \" avg \" , \" min \" , i, 0); \n "
2013-10-05 07:47:52 +02:00
" sprintf(lineBuffer, format1, \" type \" , \" sum \" , \" avg \" , \" min \" , i, 0); \n "
" sprintf(lineBuffer, format2, \" type \" , \" sum \" , \" avg \" , \" min \" , i, 0); \n "
" sprintf(lineBuffer, format3, \" type \" , \" sum \" , \" avg \" , \" min \" , i, 0); \n "
" printf(format1, \" type \" , \" sum \" , \" avg \" , \" min \" , i, 0); \n "
" printf(format2, \" type \" , \" sum \" , \" avg \" , \" min \" , i, 0); \n "
" printf(format3, \" type \" , \" sum \" , \" avg \" , \" min \" , i, 0); \n "
2016-05-19 08:22:40 +02:00
" sprintf_s(lineBuffer, 100, format1, \" type \" , \" sum \" , \" avg \" , \" min \" , i, 0); \n "
" sprintf_s(lineBuffer, 100, format2, \" type \" , \" sum \" , \" avg \" , \" min \" , i, 0); \n "
" sprintf_s(lineBuffer, 100, format3, \" type \" , \" sum \" , \" avg \" , \" min \" , i, 0); \n "
2023-03-03 18:36:27 +01:00
" } \n " , true , false , cppcheck : : Platform : : Type : : Win32A ) ;
2017-03-01 22:33:31 +01:00
ASSERT_EQUALS ( " [test.cpp:6]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'. \n "
2013-10-05 07:47:52 +02:00
" [test.cpp:6]: (warning) sprintf_s format string requires 5 parameters but 6 are given. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:7]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'. \n "
2013-10-05 07:47:52 +02:00
" [test.cpp:7]: (warning) sprintf_s format string requires 5 parameters but 6 are given. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:8]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'. \n "
2015-11-06 09:52:22 +01:00
" [test.cpp:8]: (warning) sprintf_s format string requires 5 parameters but 6 are given. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:9]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'. \n "
2013-10-05 07:47:52 +02:00
" [test.cpp:9]: (warning) sprintf format string requires 5 parameters but 6 are given. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:10]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'. \n "
2013-10-05 07:47:52 +02:00
" [test.cpp:10]: (warning) sprintf format string requires 5 parameters but 6 are given. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:11]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'. \n "
2015-11-06 09:52:22 +01:00
" [test.cpp:11]: (warning) sprintf format string requires 5 parameters but 6 are given. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:12]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'. \n "
2013-10-05 07:47:52 +02:00
" [test.cpp:12]: (warning) printf format string requires 5 parameters but 6 are given. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:13]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'. \n "
2015-11-06 09:52:22 +01:00
" [test.cpp:13]: (warning) printf format string requires 5 parameters but 6 are given. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:14]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'. \n "
2016-05-19 08:22:40 +02:00
" [test.cpp:14]: (warning) printf format string requires 5 parameters but 6 are given. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:15]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'. \n "
2016-05-19 08:22:40 +02:00
" [test.cpp:15]: (warning) sprintf_s format string requires 5 parameters but 6 are given. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:16]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'. \n "
2016-05-19 08:22:40 +02:00
" [test.cpp:16]: (warning) sprintf_s format string requires 5 parameters but 6 are given. \n "
2017-03-01 22:33:31 +01:00
" [test.cpp:17]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'. \n "
2016-05-19 08:22:40 +02:00
" [test.cpp:17]: (warning) sprintf_s format string requires 5 parameters but 6 are given. \n " , errout . str ( ) ) ;
2013-10-04 17:30:55 +02:00
2013-09-30 19:55:21 +02:00
}
2014-11-20 14:20:09 +01:00
void testMicrosoftSecureScanfArgument ( ) {
2013-09-30 19:55:21 +02:00
check ( " void foo() { \n "
" int i; \n "
" unsigned int u; \n "
" TCHAR str[10]; \n "
2013-10-01 05:49:44 +02:00
" _tscanf_s(_T( \" %s %d %u %[a-z] \" ), str, 10, &u, &i, str, 10, 0) \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32A ) ;
2013-09-30 19:55:21 +02:00
ASSERT_EQUALS ( " [test.cpp:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'. \n "
2016-01-31 14:34:26 +01:00
" [test.cpp:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'. \n "
2013-10-01 05:49:44 +02:00
" [test.cpp:5]: (warning) _tscanf_s format string requires 6 parameters but 7 are given. \n " , errout . str ( ) ) ;
2013-09-30 19:55:21 +02:00
check ( " void foo() { \n "
" int i; \n "
" unsigned int u; \n "
" TCHAR str[10]; \n "
2013-10-01 05:49:44 +02:00
" _tscanf_s(_T( \" %s %d %u %[a-z] \" ), str, 10, &u, &i, str, 10, 0) \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2013-10-01 05:49:44 +02:00
ASSERT_EQUALS ( " [test.cpp:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'. \n "
2016-01-31 14:34:26 +01:00
" [test.cpp:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'. \n "
2013-10-01 05:49:44 +02:00
" [test.cpp:5]: (warning) _tscanf_s format string requires 6 parameters but 7 are given. \n " , errout . str ( ) ) ;
check ( " void foo() { \n "
" int i; \n "
" unsigned int u; \n "
" char str[10]; \n "
" scanf_s( \" %s %d %u %[a-z] \" , str, 10, &u, &i, str, 10, 0) \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32A ) ;
2013-10-01 05:49:44 +02:00
ASSERT_EQUALS ( " [test.cpp:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'. \n "
2016-01-31 14:34:26 +01:00
" [test.cpp:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'. \n "
2013-10-01 05:49:44 +02:00
" [test.cpp:5]: (warning) scanf_s format string requires 6 parameters but 7 are given. \n " , errout . str ( ) ) ;
check ( " void foo() { \n "
" int i; \n "
" unsigned int u; \n "
" wchar_t str[10]; \n "
" wscanf_s(L \" %s %d %u %[a-z] \" , str, 10, &u, &i, str, 10, 0) \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2013-09-30 19:55:21 +02:00
ASSERT_EQUALS ( " [test.cpp:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'. \n "
2016-01-31 14:34:26 +01:00
" [test.cpp:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'. \n "
2013-10-01 05:49:44 +02:00
" [test.cpp:5]: (warning) wscanf_s format string requires 6 parameters but 7 are given. \n " , errout . str ( ) ) ;
2013-09-30 19:55:21 +02:00
2017-10-13 18:08:14 +02:00
check ( " void f() { \n "
" char str[8]; \n "
2022-01-16 12:35:51 +01:00
" scanf_s( \" %8c \" , str, sizeof(str)); \n "
" scanf_s( \" %9c \" , str, sizeof(str)); \n "
" } \n " ,
false ,
false ,
2023-03-03 18:36:27 +01:00
cppcheck : : Platform : : Type : : Win32A ) ;
2017-10-13 18:08:14 +02:00
ASSERT_EQUALS ( " [test.cpp:4]: (error) Width 9 given in format string (no. 1) is larger than destination buffer 'str[8]', use %8c to prevent overflowing it. \n " , errout . str ( ) ) ;
2013-09-30 19:55:21 +02:00
check ( " void foo() { \n "
" TCHAR txt[100]; \n "
" int i; \n "
" unsigned int u; \n "
" TCHAR str[10]; \n "
2013-10-01 05:49:44 +02:00
" _stscanf_s(txt, _T( \" %s %d %u %[a-z] \" ), str, 10, &u, &i, str, 10, 0) \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32A ) ;
2013-09-30 19:55:21 +02:00
ASSERT_EQUALS ( " [test.cpp:6]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'. \n "
2016-01-31 14:34:26 +01:00
" [test.cpp:6]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'. \n "
2013-10-01 05:49:44 +02:00
" [test.cpp:6]: (warning) _stscanf_s format string requires 6 parameters but 7 are given. \n " , errout . str ( ) ) ;
2013-09-30 19:55:21 +02:00
check ( " void foo() { \n "
" TCHAR txt[100]; \n "
" int i; \n "
" unsigned int u; \n "
" TCHAR str[10]; \n "
2013-10-01 05:49:44 +02:00
" _stscanf_s(txt, _T( \" %s %d %u %[a-z] \" ), str, 10, &u, &i, str, 10, 0) \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2013-09-30 19:55:21 +02:00
ASSERT_EQUALS ( " [test.cpp:6]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'. \n "
2016-01-31 14:34:26 +01:00
" [test.cpp:6]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'. \n "
2013-10-01 05:49:44 +02:00
" [test.cpp:6]: (warning) _stscanf_s format string requires 6 parameters but 7 are given. \n " , errout . str ( ) ) ;
check ( " void foo() { \n "
" char txt[100]; \n "
" int i; \n "
" unsigned int u; \n "
" char str[10]; \n "
" sscanf_s(txt, \" %s %d %u %[a-z] \" , str, 10, &u, &i, str, 10, 0) \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32A ) ;
2013-10-01 05:49:44 +02:00
ASSERT_EQUALS ( " [test.cpp:6]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'. \n "
2016-01-31 14:34:26 +01:00
" [test.cpp:6]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'. \n "
2013-10-01 05:49:44 +02:00
" [test.cpp:6]: (warning) sscanf_s format string requires 6 parameters but 7 are given. \n " , errout . str ( ) ) ;
check ( " void foo() { \n "
" wchar_t txt[100]; \n "
" int i; \n "
" unsigned int u; \n "
" wchar_t str[10]; \n "
" swscanf_s(txt, L \" %s %d %u %[a-z] \" , str, 10, &u, &i, str, 10, 0) \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2013-10-01 05:49:44 +02:00
ASSERT_EQUALS ( " [test.cpp:6]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'. \n "
2016-01-31 14:34:26 +01:00
" [test.cpp:6]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'. \n "
2013-10-01 05:49:44 +02:00
" [test.cpp:6]: (warning) swscanf_s format string requires 6 parameters but 7 are given. \n " , errout . str ( ) ) ;
2013-10-03 06:37:40 +02:00
check ( " void foo(FILE * fp) { \n "
" int i; \n "
" unsigned int u; \n "
" TCHAR str[10]; \n "
" _ftscanf_s(fp, _T( \" %s %d %u %[a-z] \" ), str, 10, &u, &i, str, 10, 0) \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32A ) ;
2013-10-03 06:37:40 +02:00
ASSERT_EQUALS ( " [test.cpp:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'. \n "
2016-01-31 14:34:26 +01:00
" [test.cpp:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'. \n "
2013-10-03 06:37:40 +02:00
" [test.cpp:5]: (warning) _ftscanf_s format string requires 6 parameters but 7 are given. \n " , errout . str ( ) ) ;
check ( " void foo(FILE * fp) { \n "
" int i; \n "
" unsigned int u; \n "
" TCHAR str[10]; \n "
" _ftscanf_s(fp, _T( \" %s %d %u %[a-z] \" ), str, 10, &u, &i, str, 10, 0) \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2013-10-03 06:37:40 +02:00
ASSERT_EQUALS ( " [test.cpp:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'. \n "
2016-01-31 14:34:26 +01:00
" [test.cpp:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'. \n "
2013-10-03 06:37:40 +02:00
" [test.cpp:5]: (warning) _ftscanf_s format string requires 6 parameters but 7 are given. \n " , errout . str ( ) ) ;
check ( " void foo(FILE * fp) { \n "
" int i; \n "
" unsigned int u; \n "
" char str[10]; \n "
" fscanf_s(fp, \" %s %d %u %[a-z] \" , str, 10, &u, &i, str, 10, 0) \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32A ) ;
2013-10-03 06:37:40 +02:00
ASSERT_EQUALS ( " [test.cpp:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'. \n "
2016-01-31 14:34:26 +01:00
" [test.cpp:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'. \n "
2013-10-03 06:37:40 +02:00
" [test.cpp:5]: (warning) fscanf_s format string requires 6 parameters but 7 are given. \n " , errout . str ( ) ) ;
check ( " void foo(FILE * fp) { \n "
" int i; \n "
" unsigned int u; \n "
" wchar_t str[10]; \n "
" fwscanf_s(fp, L \" %s %d %u %[a-z] \" , str, 10, &u, &i, str, 10, 0) \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2013-10-03 06:37:40 +02:00
ASSERT_EQUALS ( " [test.cpp:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'. \n "
2016-01-31 14:34:26 +01:00
" [test.cpp:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'. \n "
2013-10-03 06:37:40 +02:00
" [test.cpp:5]: (warning) fwscanf_s format string requires 6 parameters but 7 are given. \n " , errout . str ( ) ) ;
2013-10-01 05:49:44 +02:00
check ( " void foo() { \n "
" WCHAR msStr1[5] = {0}; \n "
" wscanf_s(L \" %4[^-] \" , msStr1, _countof(msStr1)); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , false , cppcheck : : Platform : : Type : : Win32W ) ;
2013-10-01 05:49:44 +02:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2013-09-30 19:55:21 +02:00
}
2014-09-24 16:45:06 +02:00
2016-08-20 08:47:52 +02:00
void testQStringFormatArguments ( ) {
check ( " void foo(float f) { \n "
" QString string; \n "
" string.sprintf( \" %d \" , f); \n "
2023-03-03 18:36:27 +01:00
" } " , false , false , cppcheck : : Platform : : Type : : Win32A ) ;
2016-08-20 08:47:52 +02:00
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'float'. \n " , errout . str ( ) ) ;
2016-08-24 12:44:57 +02:00
check ( " void foo(float f) { \n "
" QString string; \n "
" string = QString::asprintf( \" %d \" , f); \n "
2023-03-03 18:36:27 +01:00
" } " , false , false , cppcheck : : Platform : : Type : : Win32A ) ;
2016-08-24 12:44:57 +02:00
ASSERT_EQUALS ( " [test.cpp:3]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'float'. \n " , errout . str ( ) ) ;
2016-08-20 08:47:52 +02:00
}
2014-11-20 14:20:09 +01:00
void testTernary ( ) { // ticket #6182
2014-09-24 16:45:06 +02:00
check ( " void test(const std::string &val) { \n "
2017-05-18 17:23:26 +02:00
" printf( \" %s \" , val.empty() ? \" I like to eat bananas \" : val.c_str()); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2014-09-24 16:45:06 +02:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
}
2014-12-27 10:53:26 +01:00
void testUnsignedConst ( ) { // ticket #6321
check ( " void test() { \n "
" unsigned const x = 5; \n "
" printf( \" %u \" , x); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2014-12-27 10:53:26 +01:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
}
2015-10-05 10:12:30 +02:00
void testAstType ( ) { // ticket #7014
check ( " void test() { \n "
" printf( \" %c \" , \" hello \" [0]); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2015-10-05 10:12:30 +02:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2015-10-05 19:20:42 +02:00
check ( " void test() { \n "
" printf( \" %lld \" , (long long)1); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2015-10-05 19:20:42 +02:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2015-10-05 19:59:15 +02:00
check ( " void test() { \n "
" printf( \" %i \" , (short *)x); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2016-01-31 14:34:26 +01:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %i in format string (no. 1) requires 'int' but the argument type is 'signed short *'. \n " , errout . str ( ) ) ;
2016-08-14 17:19:14 +02:00
check ( " int (*fp)(); \n " // #7178 - function pointer call
" void test() { \n "
" printf( \" %i \" , fp()); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2016-08-14 17:19:14 +02:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2015-10-05 10:12:30 +02:00
}
2016-02-19 10:12:47 +01:00
void testPrintf0WithSuffix ( ) { // ticket #7069
check ( " void foo() { \n "
" printf( \" %u %lu %llu \" , 0U, 0UL, 0ULL); \n "
" printf( \" %u %lu %llu \" , 0u, 0ul, 0ull); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2016-02-19 10:12:47 +01:00
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
}
2017-10-03 22:10:13 +02:00
void testReturnValueTypeStdLib ( ) {
2017-10-05 09:02:55 +02:00
check ( " void f() { \n "
" const char *s = \" 0 \" ; \n "
" printf( \" %ld%lld \" , atol(s), atoll(s)); \n "
" } " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2019-02-15 13:29:52 +01:00
// 8141
check ( " void f(int i) { \n "
" printf( \" %f \" , imaxabs(i)); \n "
2023-03-03 18:36:27 +01:00
" } \n " , false , true , cppcheck : : Platform : : Type : : Unix64 ) ;
2019-02-15 13:29:52 +01:00
ASSERT_EQUALS ( " [test.cpp:2]: (portability) %f in format string (no. 1) requires 'double' but the argument type is 'intmax_t {aka signed long}'. \n " , errout . str ( ) ) ;
2017-10-03 22:10:13 +02:00
}
2018-01-12 08:19:21 +01:00
void testPrintfTypeAlias1 ( ) {
check ( " using INT = int; \n \n "
" using PINT = INT *; \n "
" using PCINT = const PINT; \n "
" INT i; \n "
" PINT pi; \n "
" PCINT pci; "
" void foo() { \n "
" printf( \" %d %p %p \" , i, pi, pci); \n "
" }; " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
check ( " using INT = int; \n \n "
" using PINT = INT *; \n "
" using PCINT = const PINT; \n "
" INT i; \n "
" PINT pi; \n "
" PCINT pci; "
" void foo() { \n "
" printf( \" %f %f %f \" , i, pi, pci); \n "
" }; " ) ;
ASSERT_EQUALS ( " [test.cpp:8]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'. \n "
" [test.cpp:8]: (warning) %f in format string (no. 2) requires 'double' but the argument type is 'signed int *'. \n "
" [test.cpp:8]: (warning) %f in format string (no. 3) requires 'double' but the argument type is 'const signed int *'. \n " , errout . str ( ) ) ;
}
2019-02-27 06:44:31 +01:00
void testPrintfAuto ( ) { // #8992
check ( " void f() { \n "
" auto s = sizeof(int); \n "
" printf( \" %zu \" , s); \n "
" printf( \" %f \" , s); \n "
" } \n " , false , true ) ;
ASSERT_EQUALS ( " [test.cpp:4]: (portability) %f in format string (no. 1) requires 'double' but the argument type is 'size_t {aka unsigned long}'. \n " , errout . str ( ) ) ;
}
2020-01-27 06:55:01 +01:00
void testPrintfParenthesis ( ) { // #8489
check ( " void f(int a) { \n "
" printf( \" %f \" , (a >> 24) & 0xff); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2020-01-27 06:55:01 +01:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'. \n " , errout . str ( ) ) ;
check ( " void f(int a) { \n "
" printf( \" %f \" , 0xff & (a >> 24)); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2020-01-27 06:55:01 +01:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'. \n " , errout . str ( ) ) ;
check ( " void f(int a) { \n "
" printf( \" %f \" , ((a >> 24) + 1) & 0xff); \n "
2021-02-20 12:58:42 +01:00
" } " ) ;
2020-01-27 06:55:01 +01:00
ASSERT_EQUALS ( " [test.cpp:2]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'. \n " , errout . str ( ) ) ;
}
2021-06-24 23:19:29 +02:00
void testStdDistance ( ) { // #10304
2021-06-24 23:19:59 +02:00
check ( " void foo(const std::vector<int>& IO, const int* pio) { \n "
" const auto Idx = std::distance(&IO.front(), pio); \n "
" printf( \" Idx = %td \" , Idx); \n "
" } " , /*inconclusive*/ false , /*portability*/ true ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
2021-06-24 23:19:29 +02:00
}
2022-12-15 08:52:13 +01:00
void testParameterPack ( ) { // #11289
check ( " template <typename... Args> auto f(const char* format, const Args&... args) { \n "
" return snprintf(nullptr, 0, format, args...); \n "
" } \n "
" void g() { \n "
" f( \" %d%d \" , 1, 2); \n "
" } \n " ) ;
ASSERT_EQUALS ( " " , errout . str ( ) ) ;
}
2012-05-20 21:26:48 +02:00
} ;
REGISTER_TEST ( TestIO )