test/cfg: Improved testing of std.cfg regarding uninitialized variables.

This commit is contained in:
orbitcowboy 2015-09-09 16:32:52 +02:00
parent 9bae189d9e
commit 52090f5725
4 changed files with 437 additions and 41 deletions

View File

@ -3513,7 +3513,7 @@
<arg nr="2"/>
</function>
<!-- size_t mbrtowc(wchar_t* pwc, const char* pmb, size_t max, mbstate_t* ps); -->
<function name="mbrtowc">
<function name="mbrtowc,std::mbrtowc">
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="2">
@ -3526,8 +3526,8 @@
<not-uninit/>
</arg>
</function>
<!-- wchar_t* wcstok(wchar_t *s, const wchar *ct, wchar_t **ptr); -->
<function name="wcstok">
<!-- wchar_t* wcstok(wchar_t *s, const wchar_t *ct, wchar_t **ptr); -->
<function name="wcstok,std::wcstok">
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1">
@ -3541,9 +3541,9 @@
<not-null/>
</arg>
</function>
<!-- intmax_t wcstoimax(const wchar_t *s, wchar ** endp, int base); -->
<!-- uintmax_t wcstoumax(const wchar_t *s, wchar ** endp, int base); -->
<function name="wcstoimax,wcstoumax">
<!-- intmax_t wcstoimax(const wchar_t *s, wchar_t ** endp, int base); -->
<!-- uintmax_t wcstoumax(const wchar_t *s, wchar_t ** endp, int base); -->
<function name="wcstoimax,std::wcstoimax,wcstoumax,std::wcstoumax">
<use-retval/>
<noreturn>false</noreturn>
<leak-ignore/>
@ -3560,7 +3560,7 @@
<!-- long long wcstoll(const wchar_t *s, wchar ** endp, int base); -->
<!-- unsigned long wcstoul(const wchar_t *s, wchar ** endp, int base); -->
<!-- unsigned long long wcstoull(const wchar_t *s, wchar ** endp, int base); -->
<function name="wcstol,wcstoll,wcstoul,wcstoull">
<function name="wcstol,std::wcstol,wcstoll,std::wcstoll,wcstoul,std::wcstoul,wcstoull,std::wcstoull">
<use-retval/>
<noreturn>false</noreturn>
<leak-ignore/>
@ -3574,7 +3574,7 @@
</arg>
</function>
<!-- int wprintf(const wchar_t *format, ...); -->
<function name="wprintf">
<function name="wprintf,std::wprintf">
<noreturn>false</noreturn>
<leak-ignore/>
<formatstr/>
@ -3587,7 +3587,7 @@
</arg>
</function>
<!-- int sprintf(char *s, const char *format, ...); -->
<function name="sprintf">
<function name="sprintf,std::sprintf">
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1">
@ -3595,34 +3595,40 @@
</arg>
<formatstr/>
<arg nr="2">
<not-uninit/>
<formatstr/>
<not-null/>
</arg>
<arg nr="any">
<not-uninit/>
</arg>
</function>
<!-- int swprintf(wchar_t *s, size_t n, const wchar_t *format, ...); -->
<function name="swprintf">
<function name="swprintf,std::swprintf">
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="2">
<not-uninit/>
</arg>
<arg nr="3">
<not-uninit/>
<not-null/>
</arg>
</function>
<!-- int vsprintf(char *s, const char *format, va_list arg); -->
<function name="vsprintf">
<function name="vsprintf,std::vsprintf">
<noreturn>false</noreturn>
<leak-ignore/>
<formatstr/>
<arg nr="2">
<not-uninit/>
<formatstr/>
<not-null/>
</arg>
<arg nr="3"/>
</function>
<!-- int vswprintf(wchar_t *s, size_t n, const wchar_t *format, va_list arg); -->
<function name="vswprintf">
<function name="vswprintf,std::vswprintf">
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="2">
@ -3630,13 +3636,14 @@
</arg>
<formatstr/>
<arg nr="3">
<not-uninit/>
<formatstr/>
<not-null/>
</arg>
<arg nr="4"/>
</function>
<!-- int fwprintf(FILE* stream, const wchar_t* format, ...); -->
<function name="fwprintf">
<function name="fwprintf,std::fwprintf">
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1">
@ -3644,12 +3651,16 @@
</arg>
<formatstr/>
<arg nr="2">
<not-uninit/>
<formatstr/>
<not-null/>
</arg>
<arg nr="any">
<not-uninit/>
</arg>
</function>
<!-- int snprintf(char *s, size_t n, const char *format, ...); -->
<function name="snprintf">
<function name="snprintf,std::snprintf">
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="2">
@ -3657,12 +3668,16 @@
</arg>
<formatstr/>
<arg nr="3">
<not-uninit/>
<formatstr/>
<not-null/>
</arg>
<arg nr="any">
<not-uninit/>
</arg>
</function>
<!-- int vsnprintf(char *s, size_t n, const char *format, va_list arg); -->
<function name="vsnprintf">
<function name="vsnprintf,std::vsnprintf">
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="2">
@ -3670,62 +3685,65 @@
</arg>
<formatstr/>
<arg nr="3">
<not-uninit/>
<formatstr/>
<not-null/>
</arg>
<arg nr="4"/>
</function>
<function name="fnprintf">
<noreturn>false</noreturn>
<leak-ignore/>
<formatstr/>
<arg nr="3">
<formatstr/>
</arg>
</function>
<!-- int wscanf(const wchar_t *format, ...); -->
<function name="wscanf">
<function name="wscanf,std::wscanf">
<noreturn>false</noreturn>
<leak-ignore/>
<formatstr scan="true"/>
<arg nr="1">
<not-uninit/>
<formatstr/>
<not-null/>
</arg>
</function>
<!-- int sscanf(const char *string, const char * format, ...); -->
<function name="sscanf">
<noreturn>false</noreturn>
<leak-ignore/>
<formatstr scan="true"/>
<arg nr="2">
<formatstr/>
</arg>
</function>
<!-- int fwscanf(FILE* stream, const wchar_t* format, ...); -->
<function name="fwscanf">
<function name="sscanf,std::sscanf">
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1">
<not-null/>
<not-uninit/>
</arg>
<formatstr scan="true"/>
<arg nr="2">
<formatstr/>
<not-uninit/>
<not-null/>
</arg>
</function>
<!-- int fwscanf(FILE* stream, const wchar_t* format, ...); -->
<function name="fwscanf,std::fwscanf">
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1">
<not-uninit/>
</arg>
<formatstr scan="true"/>
<arg nr="2">
<formatstr/>
<not-uninit/>
</arg>
</function>
<!-- int swscanf(const wchar_t *string, const wchar_t *format, ...); -->
<function name="swscanf">
<function name="swscanf,std::swscanf">
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1">
<not-uninit/>
</arg>
<formatstr scan="true"/>
<arg nr="2">
<formatstr/>
<not-uninit/>
</arg>
</function>
<!-- int system(const char *command); -->
<function name="system">
<function name="system,std::system">
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1">
@ -3733,7 +3751,7 @@
</arg>
</function>
<!-- /*unspecified*/ setw(int n); -->
<function name="setw">
<function name="std::setw">
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1">
@ -3741,7 +3759,7 @@
</arg>
</function>
<!-- /*unspecified*/ setiosflags(ios_base::fmtflags mask); -->
<function name="setiosflags">
<function name="std::setiosflags">
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1">

View File

@ -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

View File

@ -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);
}

View File

@ -20,6 +20,8 @@
#include <cmath>
#include <csignal>
#include <csetjmp>
#include <iostream>
#include <iomanip>
#include <cinttypes>
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
}