From 52090f57257e7c797a2d9a3bef70e03389af9bdf Mon Sep 17 00:00:00 2001 From: orbitcowboy Date: Wed, 9 Sep 2015 16:32:52 +0200 Subject: [PATCH] test/cfg: Improved testing of std.cfg regarding uninitialized variables. --- cfg/std.cfg | 96 ++++++++++++--------- test/cfg/runtests.sh | 4 +- test/cfg/std.c | 181 +++++++++++++++++++++++++++++++++++++++ test/cfg/std.cpp | 197 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 437 insertions(+), 41 deletions(-) diff --git a/cfg/std.cfg b/cfg/std.cfg index 99bb15166..fb440d570 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -3513,7 +3513,7 @@ - + false @@ -3526,8 +3526,8 @@ - - + + false @@ -3541,9 +3541,9 @@ - - - + + + false @@ -3560,7 +3560,7 @@ - + false @@ -3574,7 +3574,7 @@ - + false @@ -3587,7 +3587,7 @@ - + false @@ -3595,34 +3595,40 @@ + + + + - + false + - + false + - + false @@ -3630,13 +3636,14 @@ + - + false @@ -3644,12 +3651,16 @@ + + + + - + false @@ -3657,12 +3668,16 @@ + + + + - + false @@ -3670,62 +3685,65 @@ + - - false - - - - - - - + false + - - false - - - - - - - - + false - + + + + + false + + + + + + + + + + - + false + + + + - + false @@ -3733,7 +3751,7 @@ - + false @@ -3741,7 +3759,7 @@ - + false diff --git a/test/cfg/runtests.sh b/test/cfg/runtests.sh index 305fb38a0..bc7847e1e 100755 --- a/test/cfg/runtests.sh +++ b/test/cfg/runtests.sh @@ -14,9 +14,9 @@ CPPCHECK_OPT='--check-library --enable=information --enable=style --error-exitco # Compiler settings CXX=g++ -CXX_OPT='-fsyntax-only -std=c++0x' +CXX_OPT='-fsyntax-only -std=c++0x -Wno-format-security' CC=gcc -CC_OPT='-Wno-nonnull -Wno-implicit-function-declaration -Wno-deprecated-declarations -fsyntax-only' +CC_OPT='-Wno-nonnull -Wno-implicit-function-declaration -Wno-deprecated-declarations -Wno-format-security -fsyntax-only' # posix.c ${CC} ${CC_OPT} ${DIR}posix.c diff --git a/test/cfg/std.c b/test/cfg/std.c index 35f4f42a8..2f84fec1a 100644 --- a/test/cfg/std.c +++ b/test/cfg/std.c @@ -3169,3 +3169,184 @@ void uninivar_wcstof(void) // cppcheck-suppress uninitvar (void)wcstold(s,endp); } + +void uninivar_mbrtowc(void) +{ + wchar_t* pwc; + const char* pmb; + size_t max; + mbstate_t* ps; + // cppcheck-suppress uninitvar + (void)mbrtowc(pwc,pmb,max,ps); +} + +void uninivar_wcstok(void) +{ + wchar_t *s; + const wchar_t *ct; + wchar_t **ptr; + // cppcheck-suppress uninitvar + (void)wcstok(s,ct,ptr); +} + +void uninivar_wcstoimax(void) +{ + const wchar_t *s; + wchar_t ** endp; + int base; + // cppcheck-suppress uninitvar + (void)wcstoimax(s,endp,base); + // cppcheck-suppress uninitvar + (void)wcstoumax(s,endp,base); +} + +void uninivar_wcstol(void) +{ + const wchar_t *s; + wchar_t ** endp; + int base; + // cppcheck-suppress uninitvar + (void)wcstol(s,endp,base); + // cppcheck-suppress uninitvar + (void)wcstoll(s,endp,base); + // cppcheck-suppress uninitvar + (void)wcstoul(s,endp,base); + // cppcheck-suppress uninitvar + (void)wcstoull(s,endp,base); +} + +void uninitvar_wprintf(wchar_t *format, int input) +{ + const wchar_t *f; + int i; + // cppcheck-suppress uninitvar + (void)wprintf(f,i); + // cppcheck-suppress uninitvar + (void)wprintf(f); + // cppcheck-suppress uninitvar + (void)wprintf(f,input); + // cppcheck-suppress uninitvar + (void)wprintf(format,i); + // no warning is expected + (void)wprintf(format,input); + (void)wprintf(format); +} + +void uninitvar_sprintf(void) +{ + char *s; + const char *format; + int i; + // cppcheck-suppress uninitvar + (void)sprintf(s,format,i); +} + +void uninitvar_swprintf(void) +{ + wchar_t *s; + size_t n; + const wchar_t *format; + // cppcheck-suppress uninitvar + (void)swprintf(s,n,format); +} + +void uninitvar_vsprintf(void) +{ + char *s; + const char *format; + va_list arg; + // cppcheck-suppress va_list_usedBeforeStarted + // cppcheck-suppress uninitvar + (void)vsprintf(s,format,arg); +} + +void uninitvar_vswprintf(void) +{ + wchar_t *s; + size_t n; + const wchar_t *format; + va_list arg; + // cppcheck-suppress va_list_usedBeforeStarted + // cppcheck-suppress uninitvar + (void)vswprintf(s,n,format,arg); +} + +void uninivar_fwprintf(void) +{ + FILE* stream; + const wchar_t* format; + int i; + // cppcheck-suppress uninitvar + (void)fwprintf(stream,format,i); +} + +void uninivar_snprintf(void) +{ + char *s; + size_t n; + char *format; + int i; + // cppcheck-suppress uninitvar + (void)snprintf(s,n,format,i); +} + +void uninivar_vsnprintf(void) +{ + char *s; + size_t n; + char *format; + va_list arg; + // cppcheck-suppress va_list_usedBeforeStarted + // cppcheck-suppress uninitvar + (void)vsnprintf(s,n,format,arg); +} + +void uninivar_wscanf(void) +{ + wchar_t *format; + int i; + // cppcheck-suppress uninitvar + (void)wscanf(format); + // cppcheck-suppress uninitvar + (void)wscanf(format,&i); +} + +void uninivar_sscanf(void) +{ + char *string; + const char * format; + int i; + // cppcheck-suppress uninitvar + (void)sscanf(string,format); + // cppcheck-suppress uninitvar + (void)sscanf(string,format,&i); +} + +void uninivar_fwscanf(void) +{ + FILE* stream; + wchar_t* format; + int i; + // cppcheck-suppress uninitvar + (void)fwscanf(stream,format); + // cppcheck-suppress uninitvar + (void)fwscanf(stream,format,&i); +} + +void uninivar_swscanf(void) +{ + wchar_t* s; + wchar_t* format; + int i; + // cppcheck-suppress uninitvar + (void)swscanf(s,format); + // cppcheck-suppress uninitvar + (void)swscanf(s,format,&i); +} + +void uninitvar_system(void) +{ + char *c; + // cppcheck-suppress uninitvar + (void)system(c); +} diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index 907ae289b..b964227ea 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include void bufferAccessOutOfBounds(void) @@ -2479,3 +2481,198 @@ void uninivar_wcstof(void) // cppcheck-suppress uninitvar (void)std::wcstold(s,endp); } + +void uninivar_mbrtowc(void) +{ + wchar_t* pwc; + const char* pmb; + size_t max; + mbstate_t* ps; + // cppcheck-suppress uninitvar + (void)std::mbrtowc(pwc,pmb,max,ps); +} + +void uninivar_wcstok(void) +{ + wchar_t *s; + const wchar_t *ct; + wchar_t **ptr; + // cppcheck-suppress uninitvar + (void)std::wcstok(s,ct,ptr); +} + +void uninivar_wcstoimax(void) +{ + const wchar_t *s; + wchar_t ** endp; + int base; + // cppcheck-suppress uninitvar + (void)std::wcstoimax(s,endp,base); + // cppcheck-suppress uninitvar + (void)std::wcstoumax(s,endp,base); +} + +void uninivar_wcstol(void) +{ + const wchar_t *s; + wchar_t ** endp; + int base; + // cppcheck-suppress uninitvar + (void)std::wcstol(s,endp,base); + // cppcheck-suppress uninitvar + (void)std::wcstoll(s,endp,base); + // cppcheck-suppress uninitvar + (void)std::wcstoul(s,endp,base); + // cppcheck-suppress uninitvar + (void)std::wcstoull(s,endp,base); +} + +void uninitvar_wprintf(wchar_t *format, int input) +{ + const wchar_t *f; + int i; + // cppcheck-suppress uninitvar + (void)std::wprintf(f,i); + // cppcheck-suppress uninitvar + (void)std::wprintf(f); + // cppcheck-suppress uninitvar + (void)std::wprintf(f,input); + // cppcheck-suppress uninitvar + (void)std::wprintf(format,i); + // no warning is expected + (void)std::wprintf(format,input); + (void)std::wprintf(format); +} + +void uninitvar_sprintf(void) +{ + char *s; + const char *format; + int i; + // cppcheck-suppress uninitvar + (void)std::sprintf(s,format,i); +} + +void uninitvar_swprintf(void) +{ + wchar_t *s; + size_t n; + const wchar_t *format; + // cppcheck-suppress uninitvar + (void)std::swprintf(s,n,format); +} + +void uninitvar_vsprintf(void) +{ + char *s; + const char *format; + va_list arg; + // cppcheck-suppress va_list_usedBeforeStarted + // cppcheck-suppress uninitvar + (void)std::vsprintf(s,format,arg); +} + +void uninitvar_vswprintf(void) +{ + wchar_t *s; + size_t n; + const wchar_t *format; + va_list arg; + // cppcheck-suppress va_list_usedBeforeStarted + // cppcheck-suppress uninitvar + (void)std::vswprintf(s,n,format,arg); +} + +void uninivar_fwprintf(void) +{ + FILE* stream; + const wchar_t* format; + int i; + // cppcheck-suppress uninitvar + (void)std::fwprintf(stream,format,i); +} + +void uninivar_snprintf(void) +{ + char *s; + size_t n; + char *format; + int i; + // cppcheck-suppress uninitvar + (void)std::snprintf(s,n,format,i); +} + +void uninivar_vsnprintf(void) +{ + char *s; + size_t n; + char *format; + va_list arg; + // cppcheck-suppress va_list_usedBeforeStarted + // cppcheck-suppress uninitvar + (void)std::vsnprintf(s,n,format,arg); +} + +void uninivar_wscanf(void) +{ + wchar_t *format; + int i; + // cppcheck-suppress uninitvar + (void)std::wscanf(format); + // cppcheck-suppress uninitvar + (void)std::wscanf(format,&i); +} + +void uninivar_sscanf(void) +{ + char *string; + const char * format; + int i; + // cppcheck-suppress uninitvar + (void)std::sscanf(string,format); + // cppcheck-suppress uninitvar + (void)std::sscanf(string,format,&i); +} + +void uninivar_fwscanf(void) +{ + FILE* stream; + wchar_t* format; + int i; + // cppcheck-suppress uninitvar + (void)std::fwscanf(stream,format); + // cppcheck-suppress uninitvar + (void)std::fwscanf(stream,format,&i); +} + +void uninivar_swscanf(void) +{ + wchar_t* s; + wchar_t* format; + int i; + // cppcheck-suppress uninitvar + (void)std::swscanf(s,format); + // cppcheck-suppress uninitvar + (void)std::swscanf(s,format,&i); +} + +void uninitvar_system(void) +{ + char *c; + // cppcheck-suppress uninitvar + (void)std::system(c); +} + +void uninitvar_setw(void) +{ + int i; + // cppcheck-suppress uninitvar + std::cout << std::setw(i); +} + +void uninitvar_setiosflags(void) +{ + std::ios_base::fmtflags mask; + // cppcheck-suppress uninitvar + std::cout << std::setiosflags(mask); // #6987 - false negative +}