test/cfg: Improved testing of functions from standard namespace. Added test/cfg/*.c* files to astyle script and formatted code.

This commit is contained in:
Martin Ettl 2015-08-14 01:36:44 +02:00
parent 3ab6c5aa85
commit 77869b7812
7 changed files with 331 additions and 251 deletions

View File

@ -29,6 +29,7 @@ $ASTYLE $style $options -r gui/test/*.h
$ASTYLE $style $options lib/*.cpp $ASTYLE $style $options lib/*.cpp
$ASTYLE $style $options lib/*.h $ASTYLE $style $options lib/*.h
$ASTYLE $style $options test/*.cpp $ASTYLE $style $options test/*.cpp
$ASTYLE $style $options test/cfg/*.c*
$ASTYLE $style $options test/*.h $ASTYLE $style $options test/*.h
$ASTYLE $style $options tools/*.cpp $ASTYLE $style $options tools/*.cpp

View File

@ -9,20 +9,21 @@
#include <string.h> #include <string.h>
void leakReturnValNotUsed() { void leakReturnValNotUsed()
// cppcheck-suppress unreadVariable {
char* ptr = (char*)strdupa("test"); // cppcheck-suppress unreadVariable
// cppcheck-suppress ignoredReturnValue char* ptr = (char*)strdupa("test");
strdupa("test"); // cppcheck-suppress ignoredReturnValue
// cppcheck-suppress unreadVariable strdupa("test");
char* ptr2 = (char*)strndupa("test", 1); // cppcheck-suppress unreadVariable
// cppcheck-suppress ignoredReturnValue char* ptr2 = (char*)strndupa("test", 1);
strndupa("test", 1); // cppcheck-suppress ignoredReturnValue
// cppcheck-suppress ignoredReturnValue strndupa("test", 1);
// cppcheck-suppress nullPointer // cppcheck-suppress ignoredReturnValue
strcasestr("test", NULL); // cppcheck-suppress nullPointer
strcasestr("test", NULL);
//
if (42 == __builtin_expect(42, 0)) //
return; if (42 == __builtin_expect(42, 0))
return;
} }

View File

@ -19,49 +19,53 @@
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
void bufferAccessOutOfBounds(int fd) { void bufferAccessOutOfBounds(int fd)
char a[5]; {
read(fd,a,5); char a[5];
// cppcheck-suppress bufferAccessOutOfBounds read(fd,a,5);
read(fd,a,6); // cppcheck-suppress bufferAccessOutOfBounds
write(fd,a,5); read(fd,a,6);
// cppcheck-suppress bufferAccessOutOfBounds write(fd,a,5);
write(fd,a,6); // cppcheck-suppress bufferAccessOutOfBounds
recv(fd,a,5,0); write(fd,a,6);
// cppcheck-suppress bufferAccessOutOfBounds recv(fd,a,5,0);
recv(fd,a,6,0); // cppcheck-suppress bufferAccessOutOfBounds
recvfrom(fd,a,5,0,0x0,0x0); recv(fd,a,6,0);
// cppcheck-suppress bufferAccessOutOfBounds recvfrom(fd,a,5,0,0x0,0x0);
recvfrom(fd,a,6,0,0x0,0x0); // cppcheck-suppress bufferAccessOutOfBounds
send(fd,a,5,0); recvfrom(fd,a,6,0,0x0,0x0);
// cppcheck-suppress bufferAccessOutOfBounds send(fd,a,5,0);
send(fd,a,6,0); // cppcheck-suppress bufferAccessOutOfBounds
sendto(fd,a,5,0,0x0,0x0); send(fd,a,6,0);
// cppcheck-suppress bufferAccessOutOfBounds sendto(fd,a,5,0,0x0,0x0);
sendto(fd,a,6,0,0x0,0x0); // cppcheck-suppress bufferAccessOutOfBounds
// cppcheck-suppress constStatement sendto(fd,a,6,0,0x0,0x0);
0; // cppcheck-suppress constStatement
0;
} }
void nullPointer(char *p) { void nullPointer(char *p)
{
// cppcheck-suppress ignoredReturnValue // cppcheck-suppress ignoredReturnValue
isatty (0); isatty(0);
mkdir (p, 0); mkdir(p, 0);
getcwd (0, 0); getcwd(0, 0);
// cppcheck-suppress nullPointer // cppcheck-suppress nullPointer
readdir (0); readdir(0);
// cppcheck-suppress nullPointer // cppcheck-suppress nullPointer
utime(NULL, NULL); utime(NULL, NULL);
} }
void memleak_getaddrinfo() { void memleak_getaddrinfo()
//TODO: nothing to report yet, see http://sourceforge.net/p/cppcheck/discussion/general/thread/d9737d5d/ {
struct addrinfo * res=NULL; //TODO: nothing to report yet, see http://sourceforge.net/p/cppcheck/discussion/general/thread/d9737d5d/
getaddrinfo("node", NULL, NULL, &res); struct addrinfo * res=NULL;
freeaddrinfo(res); getaddrinfo("node", NULL, NULL, &res);
freeaddrinfo(res);
} }
void memleak_mmap(int fd) { void memleak_mmap(int fd)
{
// cppcheck-suppress unreadVariable // cppcheck-suppress unreadVariable
void *addr = mmap(NULL, 255, PROT_NONE, MAP_PRIVATE, fd, 0); void *addr = mmap(NULL, 255, PROT_NONE, MAP_PRIVATE, fd, 0);
// cppcheck-suppress memleak // cppcheck-suppress memleak
@ -74,40 +78,48 @@ void resourceLeak_fdopen(int fd) {
} }
*/ */
void resourceLeak_fdopendir(int fd) { void resourceLeak_fdopendir(int fd)
{
// cppcheck-suppress unreadVariable // cppcheck-suppress unreadVariable
DIR* leak1 = fdopendir(fd); DIR* leak1 = fdopendir(fd);
// cppcheck-suppress resourceLeak // cppcheck-suppress resourceLeak
} }
void resourceLeak_opendir(void) { void resourceLeak_opendir(void)
{
// cppcheck-suppress unreadVariable // cppcheck-suppress unreadVariable
DIR* leak1 = opendir("abc"); DIR* leak1 = opendir("abc");
// cppcheck-suppress resourceLeak // cppcheck-suppress resourceLeak
} }
void resourceLeak_socket(void) { void resourceLeak_socket(void)
{
// cppcheck-suppress unreadVariable // cppcheck-suppress unreadVariable
int s = socket(AF_INET, SOCK_STREAM, 0); int s = socket(AF_INET, SOCK_STREAM, 0);
// cppcheck-suppress resourceLeak // cppcheck-suppress resourceLeak
} }
void noleak(int x, int y, int z) { void noleak(int x, int y, int z)
DIR *p1 = fdopendir(x); closedir(p1); {
DIR *p2 = opendir("abc"); closedir(p2); DIR *p1 = fdopendir(x);
int s = socket(AF_INET,SOCK_STREAM,0); close(s); closedir(p1);
/* TODO: add configuration for open/fdopen DIR *p2 = opendir("abc");
// #2830 closedir(p2);
int fd = open("path", O_RDONLY); int s = socket(AF_INET,SOCK_STREAM,0);
FILE *f = fdopen(fd, "rt"); close(s);
fclose(f); /* TODO: add configuration for open/fdopen
*/ // #2830
int fd = open("path", O_RDONLY);
FILE *f = fdopen(fd, "rt");
fclose(f);
*/
} }
// unused return value // unused return value
void ignoredReturnValue(void *addr, int fd) { void ignoredReturnValue(void *addr, int fd)
{
// cppcheck-suppress ignoredReturnValue // cppcheck-suppress ignoredReturnValue
// cppcheck-suppress leakReturnValNotUsed // cppcheck-suppress leakReturnValNotUsed
mmap(addr, 255, PROT_NONE, MAP_PRIVATE, fd, 0); mmap(addr, 255, PROT_NONE, MAP_PRIVATE, fd, 0);
@ -120,7 +132,8 @@ void ignoredReturnValue(void *addr, int fd) {
// valid range // valid range
void invalidFunctionArg() { void invalidFunctionArg()
{
// cppcheck-suppress invalidFunctionArg // cppcheck-suppress invalidFunctionArg
usleep(-1); usleep(-1);
usleep(0); usleep(0);
@ -129,10 +142,11 @@ void invalidFunctionArg() {
usleep(1000000); usleep(1000000);
} }
void uninitvar(int fd) { void uninitvar(int fd)
{
int x; int x;
char buf[2]; char buf[2];
int decimal, sign; int decimal, sign;
double d; double d;
// cppcheck-suppress uninitvar // cppcheck-suppress uninitvar
write(x,"ab",2); write(x,"ab",2);
@ -140,8 +154,8 @@ void uninitvar(int fd) {
write(fd,buf,2); write(fd,buf,2);
// cppcheck-suppress uninitvar // cppcheck-suppress uninitvar
write(fd,"ab",x); write(fd,"ab",x);
/* int regcomp(regex_t *restrict preg, const char *restrict pattern, int cflags); */ /* int regcomp(regex_t *restrict preg, const char *restrict pattern, int cflags); */
regex_t reg; regex_t reg;
const char * pattern; const char * pattern;
@ -151,12 +165,12 @@ void uninitvar(int fd) {
pattern=""; pattern="";
// cppcheck-suppress uninitvar // cppcheck-suppress uninitvar
regcomp(&reg, pattern, cflags); regcomp(&reg, pattern, cflags);
regerror (0, &reg, 0, 0); regerror(0, &reg, 0, 0);
// cppcheck-suppress uninitvar // cppcheck-suppress uninitvar
// cppcheck-suppress unreadVariable // cppcheck-suppress unreadVariable
char *buffer = ecvt(d, 11, &decimal, &sign); char *buffer = ecvt(d, 11, &decimal, &sign);
gcvt(3.141, 2, buf); gcvt(3.141, 2, buf);
char *filename; char *filename;
struct utimbuf *times; struct utimbuf *times;
// cppcheck-suppress uninitvar // cppcheck-suppress uninitvar
@ -167,7 +181,8 @@ void uninitvar(int fd) {
} }
void uninitvar_types(void) { void uninitvar_types(void)
{
// cppcheck-suppress unassignedVariable // cppcheck-suppress unassignedVariable
blkcnt_t b; blkcnt_t b;
// cppcheck-suppress uninitvar // cppcheck-suppress uninitvar
@ -178,12 +193,13 @@ void uninitvar_types(void) {
d.d_ino + 1; d.d_ino + 1;
} }
void timet_h() { void timet_h()
struct timespec* ptp; {
// cppcheck-suppress uninitvar struct timespec* ptp;
clock_settime(CLOCK_REALTIME, ptp); // cppcheck-suppress uninitvar
clock_settime(CLOCK_REALTIME, ptp);
time_t clock = time(0);
char buf[26]; time_t clock = time(0);
ctime_r(&clock, buf); char buf[26];
ctime_r(&clock, buf);
} }

View File

@ -10,7 +10,7 @@ else # assume we are in repo root
fi fi
# Cppcheck options # Cppcheck options
CPPCHECK_OPT='--check-library --enable=information --enable=style --error-exitcode=1 --suppress=missingIncludeSystem --inline-suppr' CPPCHECK_OPT='--check-library --enable=information --enable=style --error-exitcode=1 --suppress=missingIncludeSystem --inline-suppr --template="{file}:{line}:{severity}:{id}:{message}"'
# Compiler settings # Compiler settings
CXX=g++ CXX=g++

View File

@ -12,40 +12,42 @@
#include <stdlib.h> #include <stdlib.h>
#include <tgmath.h> // frexp #include <tgmath.h> // frexp
void bufferAccessOutOf(void) { void bufferAccessOutOfBounds(void)
char a[5]; {
fgets(a,5,stdin); char a[5];
// cppcheck-suppress bufferAccessOutOfBounds fgets(a,5,stdin);
fgets(a,6,stdin); // cppcheck-suppress bufferAccessOutOfBounds
sprintf(a, "ab%s", "cd"); fgets(a,6,stdin);
// cppcheck-suppress bufferAccessOutOfBounds sprintf(a, "ab%s", "cd");
// cppcheck-suppress redundantCopy // cppcheck-suppress bufferAccessOutOfBounds
sprintf(a, "ab%s", "cde"); // cppcheck-suppress redundantCopy
// cppcheck-suppress redundantCopy sprintf(a, "ab%s", "cde");
snprintf(a, 5, "abcde%i", 1); // cppcheck-suppress redundantCopy
// cppcheck-suppress redundantCopy snprintf(a, 5, "abcde%i", 1);
snprintf(a, 6, "abcde%i", 1); //TODO: cppcheck-suppress bufferAccessOutOfBounds // cppcheck-suppress redundantCopy
// cppcheck-suppress redundantCopy snprintf(a, 6, "abcde%i", 1); //TODO: cppcheck-suppress bufferAccessOutOfBounds
strcpy(a,"abcd"); // cppcheck-suppress redundantCopy
// cppcheck-suppress bufferAccessOutOfBounds strcpy(a,"abcd");
// cppcheck-suppress redundantCopy // cppcheck-suppress bufferAccessOutOfBounds
strcpy(a, "abcde"); // cppcheck-suppress redundantCopy
// cppcheck-suppress redundantCopy strcpy(a, "abcde");
strncpy(a,"abcde",5); // cppcheck-suppress redundantCopy
// cppcheck-suppress bufferAccessOutOfBounds strncpy(a,"abcde",5);
// cppcheck-suppress redundantCopy // cppcheck-suppress bufferAccessOutOfBounds
strncpy(a,"abcde",6); // cppcheck-suppress redundantCopy
fread(a,1,5,stdin); strncpy(a,"abcde",6);
// cppcheck-suppress bufferAccessOutOfBounds fread(a,1,5,stdin);
fread(a,1,6,stdin); // cppcheck-suppress bufferAccessOutOfBounds
fwrite(a,1,5,stdout); fread(a,1,6,stdin);
// cppcheck-suppress bufferAccessOutOfBounds fwrite(a,1,5,stdout);
fread(a,1,6,stdout); // cppcheck-suppress bufferAccessOutOfBounds
fread(a,1,6,stdout);
} }
// memory leak // memory leak
void ignoreleak(void) { void ignoreleak(void)
{
char *p = (char *)malloc(10); char *p = (char *)malloc(10);
memset(&(p[0]), 0, 10); memset(&(p[0]), 0, 10);
// cppcheck-suppress memleak // cppcheck-suppress memleak
@ -53,142 +55,152 @@ void ignoreleak(void) {
// null pointer // null pointer
void nullpointer(int value){ void nullpointer(int value)
int res = 0; {
FILE *fp; int res = 0;
FILE *fp;
// cppcheck-suppress nullPointer // cppcheck-suppress nullPointer
clearerr(0); clearerr(0);
// cppcheck-suppress ignoredReturnValue // cppcheck-suppress ignoredReturnValue
// cppcheck-suppress nullPointer // cppcheck-suppress nullPointer
feof(0); feof(0);
// cppcheck-suppress nullPointer // cppcheck-suppress nullPointer
fgetc(0); fgetc(0);
// cppcheck-suppress nullPointer // cppcheck-suppress nullPointer
fclose(0); fclose(0);
// cppcheck-suppress ignoredReturnValue // cppcheck-suppress ignoredReturnValue
// cppcheck-suppress nullPointer // cppcheck-suppress nullPointer
ferror(0); ferror(0);
// cppcheck-suppress nullPointer // cppcheck-suppress nullPointer
ftell(0); ftell(0);
// cppcheck-suppress nullPointer // cppcheck-suppress nullPointer
puts(0); puts(0);
// cppcheck-suppress nullPointer // cppcheck-suppress nullPointer
fp=fopen(0,0); fp=fopen(0,0);
fclose(fp); fp = 0; fclose(fp);
// No FP fp = 0;
fflush(0); // No FP
// No FP fflush(0);
// cppcheck-suppress redundantAssignment // No FP
fp = freopen(0,"abc",stdin); // cppcheck-suppress redundantAssignment
fclose(fp); fp = 0; fp = freopen(0,"abc",stdin);
// cppcheck-suppress nullPointer fclose(fp);
fputc(0,0); fp = 0;
// cppcheck-suppress nullPointer // cppcheck-suppress nullPointer
fputs(0,0); fputc(0,0);
// cppcheck-suppress nullPointer // cppcheck-suppress nullPointer
fgetpos(0,0); fputs(0,0);
// cppcheck-suppress nullPointer // cppcheck-suppress nullPointer
frexp(1.0,0); fgetpos(0,0);
// cppcheck-suppress nullPointer // cppcheck-suppress nullPointer
fsetpos(0,0); frexp(1.0,0);
// cppcheck-suppress nullPointer // cppcheck-suppress nullPointer
itoa(123,0,10); fsetpos(0,0);
putchar(0); // cppcheck-suppress nullPointer
// cppcheck-suppress ignoredReturnValue itoa(123,0,10);
// cppcheck-suppress nullPointer putchar(0);
strchr(0,0); // cppcheck-suppress ignoredReturnValue
// cppcheck-suppress ignoredReturnValue // cppcheck-suppress nullPointer
// cppcheck-suppress nullPointer strchr(0,0);
strlen(0); // cppcheck-suppress ignoredReturnValue
// cppcheck-suppress nullPointer // cppcheck-suppress nullPointer
strcpy(0,0); strlen(0);
// cppcheck-suppress ignoredReturnValue // cppcheck-suppress nullPointer
// cppcheck-suppress nullPointer strcpy(0,0);
strspn(0,0); // cppcheck-suppress ignoredReturnValue
// cppcheck-suppress ignoredReturnValue // cppcheck-suppress nullPointer
// cppcheck-suppress nullPointer strspn(0,0);
strcspn(0,0); // cppcheck-suppress ignoredReturnValue
// cppcheck-suppress ignoredReturnValue // cppcheck-suppress nullPointer
// cppcheck-suppress nullPointer strcspn(0,0);
strcoll(0,0); // cppcheck-suppress ignoredReturnValue
// cppcheck-suppress nullPointer // cppcheck-suppress nullPointer
strcat(0,0); strcoll(0,0);
// cppcheck-suppress ignoredReturnValue // cppcheck-suppress nullPointer
// cppcheck-suppress nullPointer strcat(0,0);
strcmp(0,0); // cppcheck-suppress ignoredReturnValue
// cppcheck-suppress nullPointer // cppcheck-suppress nullPointer
strncpy(0,0,1); strcmp(0,0);
// cppcheck-suppress nullPointer // cppcheck-suppress nullPointer
strncat(0,0,1); strncpy(0,0,1);
// cppcheck-suppress ignoredReturnValue // cppcheck-suppress nullPointer
// cppcheck-suppress nullPointer strncat(0,0,1);
strncmp(0,0,1); // cppcheck-suppress ignoredReturnValue
// cppcheck-suppress ignoredReturnValue // cppcheck-suppress nullPointer
// cppcheck-suppress nullPointer strncmp(0,0,1);
strstr(0,0); // cppcheck-suppress ignoredReturnValue
// cppcheck-suppress nullPointer // cppcheck-suppress nullPointer
strtoul(0,0,0); strstr(0,0);
// cppcheck-suppress nullPointer // cppcheck-suppress nullPointer
strtoull(0,0,0); strtoul(0,0,0);
// cppcheck-suppress nullPointer // cppcheck-suppress nullPointer
strtol(0,0,0); strtoull(0,0,0);
// cppcheck-suppress nullPointer
strtol(0,0,0);
// #6100 False positive nullPointer - calling mbstowcs(NULL,) // #6100 False positive nullPointer - calling mbstowcs(NULL,)
res += mbstowcs(0,"",0); res += mbstowcs(0,"",0);
// cppcheck-suppress unreadVariable // cppcheck-suppress unreadVariable
res += wcstombs(0,L"",0); res += wcstombs(0,L"",0);
strtok(NULL,"xyz"); strtok(NULL,"xyz");
strxfrm(0,"foo",0); strxfrm(0,"foo",0);
// TODO: error message // TODO: error message
strxfrm(0,"foo",42); strxfrm(0,"foo",42);
snprintf(NULL, 0, "someformatstring"); // legal snprintf(NULL, 0, "someformatstring"); // legal
// cppcheck-suppress nullPointer // cppcheck-suppress nullPointer
snprintf(NULL, 42, "someformatstring"); // not legal snprintf(NULL, 42, "someformatstring"); // not legal
} }
void nullpointerMemchr1(char *p, char *s) { void nullpointerMemchr1(char *p, char *s)
// cppcheck-suppress uselessAssignmentPtrArg {
p = memchr (s, 'p', strlen(s)); // cppcheck-suppress uselessAssignmentPtrArg
p = memchr(s, 'p', strlen(s));
} }
void nullpointerMemchr2(char *p, char *s) { void nullpointerMemchr2(char *p, char *s)
// cppcheck-suppress uselessAssignmentPtrArg {
p = memchr (s, 0, strlen(s)); // cppcheck-suppress uselessAssignmentPtrArg
p = memchr(s, 0, strlen(s));
} }
void nullpointerMemchr3(char *p) { void nullpointerMemchr3(char *p)
char *s = 0; {
// cppcheck-suppress nullPointer char *s = 0;
// cppcheck-suppress uselessAssignmentPtrArg // cppcheck-suppress nullPointer
p = memchr (s, 0, strlen(s)); // cppcheck-suppress uselessAssignmentPtrArg
p = memchr(s, 0, strlen(s));
} }
void nullpointerMemcmp(char *p) { void nullpointerMemcmp(char *p)
// cppcheck-suppress ignoredReturnValue {
// cppcheck-suppress nullPointer // cppcheck-suppress ignoredReturnValue
memcmp(p, 0, 123); // cppcheck-suppress nullPointer
memcmp(p, 0, 123);
} }
// uninit pointers // uninit pointers
void uninit_clearerr(void) { void uninit_clearerr(void)
{
FILE *fp; FILE *fp;
// cppcheck-suppress uninitvar // cppcheck-suppress uninitvar
clearerr(fp); clearerr(fp);
} }
void uninit_fclose(void) { void uninit_fclose(void)
{
FILE *fp; FILE *fp;
// cppcheck-suppress uninitvar // cppcheck-suppress uninitvar
fclose(fp); fclose(fp);
} }
void uninit_fopen(void) { void uninit_fopen(void)
{
const char *filename, *mode; const char *filename, *mode;
FILE *fp; FILE *fp;
// cppcheck-suppress uninitvar // cppcheck-suppress uninitvar
@ -199,33 +211,38 @@ void uninit_fopen(void) {
fclose(fp); fclose(fp);
} }
void uninit_feof(void) { void uninit_feof(void)
{
FILE *fp; FILE *fp;
// cppcheck-suppress ignoredReturnValue // cppcheck-suppress ignoredReturnValue
// cppcheck-suppress uninitvar // cppcheck-suppress uninitvar
feof(fp); feof(fp);
} }
void uninit_ferror(void) { void uninit_ferror(void)
{
FILE *fp; FILE *fp;
// cppcheck-suppress ignoredReturnValue // cppcheck-suppress ignoredReturnValue
// cppcheck-suppress uninitvar // cppcheck-suppress uninitvar
ferror(fp); ferror(fp);
} }
void uninit_fflush(void) { void uninit_fflush(void)
{
FILE *fp; FILE *fp;
// cppcheck-suppress uninitvar // cppcheck-suppress uninitvar
fflush(fp); fflush(fp);
} }
void uninit_fgetc(void) { void uninit_fgetc(void)
{
FILE *fp; FILE *fp;
// cppcheck-suppress uninitvar // cppcheck-suppress uninitvar
fgetc(fp); fgetc(fp);
} }
void uninit_fgetpos(void) { void uninit_fgetpos(void)
{
FILE *fp; FILE *fp;
fpos_t pos; fpos_t pos;
fpos_t *ppos; fpos_t *ppos;
@ -238,7 +255,8 @@ void uninit_fgetpos(void) {
fclose(fp); fclose(fp);
} }
void uninit_fsetpos(void) { void uninit_fsetpos(void)
{
FILE *fp; FILE *fp;
fpos_t pos; fpos_t pos;
fpos_t *ppos; fpos_t *ppos;
@ -251,7 +269,8 @@ void uninit_fsetpos(void) {
fclose(fp); fclose(fp);
} }
void uninit_fgets(void) { void uninit_fgets(void)
{
FILE *fp; FILE *fp;
char buf[10]; char buf[10];
char *str; char *str;
@ -265,7 +284,8 @@ void uninit_fgets(void) {
fgets(buf,10,fp); fgets(buf,10,fp);
} }
void uninit_fputc(void) { void uninit_fputc(void)
{
int i; int i;
FILE *fp; FILE *fp;
@ -278,7 +298,8 @@ void uninit_fputc(void) {
fputc('a', fp); fputc('a', fp);
} }
void uninit_fputs(void) { void uninit_fputs(void)
{
const char *s; const char *s;
FILE *fp; FILE *fp;
@ -291,26 +312,30 @@ void uninit_fputs(void) {
fputs("a", fp); fputs("a", fp);
} }
void uninit_ftell(void) { void uninit_ftell(void)
{
FILE *fp; FILE *fp;
// cppcheck-suppress uninitvar // cppcheck-suppress uninitvar
ftell(fp); ftell(fp);
} }
void uninit_puts(void) { void uninit_puts(void)
{
const char *s; const char *s;
// cppcheck-suppress uninitvar // cppcheck-suppress uninitvar
puts(s); puts(s);
} }
void uninit_putchar(void) { void uninit_putchar(void)
{
char c; char c;
// cppcheck-suppress uninitvar // cppcheck-suppress uninitvar
putchar(c); putchar(c);
} }
void ignoreretrn(void) { void ignoreretrn(void)
char szNumbers[] = "2001 60c0c0 -1101110100110100100000 0x6fffff"; {
char * pEnd; char szNumbers[] = "2001 60c0c0 -1101110100110100100000 0x6fffff";
strtol (szNumbers,&pEnd,10); char * pEnd;
strtol(szNumbers,&pEnd,10);
} }

View File

@ -10,16 +10,52 @@
#include <cstring> #include <cstring>
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <ctime>
#include <cctype>
void bufferAccessOutOf(void) { void bufferAccessOutOfBounds(void)
char a[5]; {
std::strcpy(a,"abcd"); char a[5];
// cppcheck-suppress bufferAccessOutOfBounds std::strcpy(a,"abcd");
// cppcheck-suppress redundantCopy // cppcheck-suppress bufferAccessOutOfBounds
std::strcpy(a, "abcde"); // cppcheck-suppress redundantCopy
// cppcheck-suppress redundantCopy std::strcpy(a, "abcde");
std::strncpy(a,"abcde",5); // cppcheck-suppress redundantCopy
// cppcheck-suppress bufferAccessOutOfBounds std::strncpy(a,"abcde",5);
// cppcheck-suppress redundantCopy // cppcheck-suppress bufferAccessOutOfBounds
std::strncpy(a,"abcde",6); // cppcheck-suppress redundantCopy
std::strncpy(a,"abcde",6);
}
void uninitvar(void)
{
int i;
// cppcheck-suppress uninitvar
std::abs(i);
// cppcheck-suppress uninitvar
std::isalnum(i);
// cppcheck-suppress uninitvar
std::isalpha(i);
// cppcheck-suppress uninitvar
std::iscntrl(i);
// cppcheck-suppress uninitvar
std::isdigit(i);
// cppcheck-suppress uninitvar
std::isgraph(i);
// cppcheck-suppress uninitvar
std::islower(i);
// cppcheck-suppress uninitvar
std::isprint(i);
// cppcheck-suppress uninitvar
std::isspace(i);
// cppcheck-suppress uninitvar
std::isupper(i);
// cppcheck-suppress uninitvar
std::isxdigit(i);
const struct tm *tm;
// cppcheck-suppress uninitvar
// cppcheck-suppress obsoleteFunctionsasctime
std::asctime(tm);
} }

View File

@ -7,12 +7,13 @@
// //
class CSharedFilesCtrl { class CSharedFilesCtrl {
void OpenFile(const CShareableFile* file, int, int); void OpenFile(const CShareableFile* file, int, int);
afx_msg void OnNmDblClk(NMHDR *pNMHDR, LRESULT *pResult); afx_msg void OnNmDblClk(NMHDR *pNMHDR, LRESULT *pResult);
}; };
void CSharedFilesCtrl::OnNmDblClk(NMHDR* /*pNMHDR*/, LRESULT* pResult) { void CSharedFilesCtrl::OnNmDblClk(NMHDR* /*pNMHDR*/, LRESULT* pResult)
if (file) {
OpenFile(file,0,0); // <- not the windows OpenFile function if (file)
OpenFile(file,0,0); // <- not the windows OpenFile function
} }