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:
parent
3ab6c5aa85
commit
77869b7812
|
@ -29,6 +29,7 @@ $ASTYLE $style $options -r gui/test/*.h
|
|||
$ASTYLE $style $options lib/*.cpp
|
||||
$ASTYLE $style $options lib/*.h
|
||||
$ASTYLE $style $options test/*.cpp
|
||||
$ASTYLE $style $options test/cfg/*.c*
|
||||
$ASTYLE $style $options test/*.h
|
||||
|
||||
$ASTYLE $style $options tools/*.cpp
|
||||
|
|
|
@ -9,20 +9,21 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
void leakReturnValNotUsed() {
|
||||
// cppcheck-suppress unreadVariable
|
||||
char* ptr = (char*)strdupa("test");
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
strdupa("test");
|
||||
// cppcheck-suppress unreadVariable
|
||||
char* ptr2 = (char*)strndupa("test", 1);
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
strndupa("test", 1);
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress nullPointer
|
||||
strcasestr("test", NULL);
|
||||
|
||||
//
|
||||
if (42 == __builtin_expect(42, 0))
|
||||
return;
|
||||
void leakReturnValNotUsed()
|
||||
{
|
||||
// cppcheck-suppress unreadVariable
|
||||
char* ptr = (char*)strdupa("test");
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
strdupa("test");
|
||||
// cppcheck-suppress unreadVariable
|
||||
char* ptr2 = (char*)strndupa("test", 1);
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
strndupa("test", 1);
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress nullPointer
|
||||
strcasestr("test", NULL);
|
||||
|
||||
//
|
||||
if (42 == __builtin_expect(42, 0))
|
||||
return;
|
||||
}
|
||||
|
|
142
test/cfg/posix.c
142
test/cfg/posix.c
|
@ -19,49 +19,53 @@
|
|||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void bufferAccessOutOfBounds(int fd) {
|
||||
char a[5];
|
||||
read(fd,a,5);
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
read(fd,a,6);
|
||||
write(fd,a,5);
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
write(fd,a,6);
|
||||
recv(fd,a,5,0);
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
recv(fd,a,6,0);
|
||||
recvfrom(fd,a,5,0,0x0,0x0);
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
recvfrom(fd,a,6,0,0x0,0x0);
|
||||
send(fd,a,5,0);
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
send(fd,a,6,0);
|
||||
sendto(fd,a,5,0,0x0,0x0);
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
sendto(fd,a,6,0,0x0,0x0);
|
||||
// cppcheck-suppress constStatement
|
||||
0;
|
||||
void bufferAccessOutOfBounds(int fd)
|
||||
{
|
||||
char a[5];
|
||||
read(fd,a,5);
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
read(fd,a,6);
|
||||
write(fd,a,5);
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
write(fd,a,6);
|
||||
recv(fd,a,5,0);
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
recv(fd,a,6,0);
|
||||
recvfrom(fd,a,5,0,0x0,0x0);
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
recvfrom(fd,a,6,0,0x0,0x0);
|
||||
send(fd,a,5,0);
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
send(fd,a,6,0);
|
||||
sendto(fd,a,5,0,0x0,0x0);
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
sendto(fd,a,6,0,0x0,0x0);
|
||||
// cppcheck-suppress constStatement
|
||||
0;
|
||||
}
|
||||
|
||||
void nullPointer(char *p) {
|
||||
void nullPointer(char *p)
|
||||
{
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
isatty (0);
|
||||
mkdir (p, 0);
|
||||
getcwd (0, 0);
|
||||
isatty(0);
|
||||
mkdir(p, 0);
|
||||
getcwd(0, 0);
|
||||
// cppcheck-suppress nullPointer
|
||||
readdir (0);
|
||||
readdir(0);
|
||||
// cppcheck-suppress nullPointer
|
||||
utime(NULL, NULL);
|
||||
}
|
||||
|
||||
void memleak_getaddrinfo() {
|
||||
//TODO: nothing to report yet, see http://sourceforge.net/p/cppcheck/discussion/general/thread/d9737d5d/
|
||||
struct addrinfo * res=NULL;
|
||||
getaddrinfo("node", NULL, NULL, &res);
|
||||
freeaddrinfo(res);
|
||||
void memleak_getaddrinfo()
|
||||
{
|
||||
//TODO: nothing to report yet, see http://sourceforge.net/p/cppcheck/discussion/general/thread/d9737d5d/
|
||||
struct addrinfo * res=NULL;
|
||||
getaddrinfo("node", NULL, NULL, &res);
|
||||
freeaddrinfo(res);
|
||||
}
|
||||
|
||||
void memleak_mmap(int fd) {
|
||||
void memleak_mmap(int fd)
|
||||
{
|
||||
// cppcheck-suppress unreadVariable
|
||||
void *addr = mmap(NULL, 255, PROT_NONE, MAP_PRIVATE, fd, 0);
|
||||
// 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
|
||||
DIR* leak1 = fdopendir(fd);
|
||||
// cppcheck-suppress resourceLeak
|
||||
}
|
||||
|
||||
void resourceLeak_opendir(void) {
|
||||
void resourceLeak_opendir(void)
|
||||
{
|
||||
// cppcheck-suppress unreadVariable
|
||||
DIR* leak1 = opendir("abc");
|
||||
// cppcheck-suppress resourceLeak
|
||||
}
|
||||
|
||||
void resourceLeak_socket(void) {
|
||||
void resourceLeak_socket(void)
|
||||
{
|
||||
// cppcheck-suppress unreadVariable
|
||||
int s = socket(AF_INET, SOCK_STREAM, 0);
|
||||
// cppcheck-suppress resourceLeak
|
||||
}
|
||||
|
||||
void noleak(int x, int y, int z) {
|
||||
DIR *p1 = fdopendir(x); closedir(p1);
|
||||
DIR *p2 = opendir("abc"); closedir(p2);
|
||||
int s = socket(AF_INET,SOCK_STREAM,0); close(s);
|
||||
/* TODO: add configuration for open/fdopen
|
||||
// #2830
|
||||
int fd = open("path", O_RDONLY);
|
||||
FILE *f = fdopen(fd, "rt");
|
||||
fclose(f);
|
||||
*/
|
||||
void noleak(int x, int y, int z)
|
||||
{
|
||||
DIR *p1 = fdopendir(x);
|
||||
closedir(p1);
|
||||
DIR *p2 = opendir("abc");
|
||||
closedir(p2);
|
||||
int s = socket(AF_INET,SOCK_STREAM,0);
|
||||
close(s);
|
||||
/* TODO: add configuration for open/fdopen
|
||||
// #2830
|
||||
int fd = open("path", O_RDONLY);
|
||||
FILE *f = fdopen(fd, "rt");
|
||||
fclose(f);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
// unused return value
|
||||
|
||||
void ignoredReturnValue(void *addr, int fd) {
|
||||
void ignoredReturnValue(void *addr, int fd)
|
||||
{
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress leakReturnValNotUsed
|
||||
mmap(addr, 255, PROT_NONE, MAP_PRIVATE, fd, 0);
|
||||
|
@ -120,7 +132,8 @@ void ignoredReturnValue(void *addr, int fd) {
|
|||
|
||||
// valid range
|
||||
|
||||
void invalidFunctionArg() {
|
||||
void invalidFunctionArg()
|
||||
{
|
||||
// cppcheck-suppress invalidFunctionArg
|
||||
usleep(-1);
|
||||
usleep(0);
|
||||
|
@ -129,10 +142,11 @@ void invalidFunctionArg() {
|
|||
usleep(1000000);
|
||||
}
|
||||
|
||||
void uninitvar(int fd) {
|
||||
void uninitvar(int fd)
|
||||
{
|
||||
int x;
|
||||
char buf[2];
|
||||
int decimal, sign;
|
||||
int decimal, sign;
|
||||
double d;
|
||||
// cppcheck-suppress uninitvar
|
||||
write(x,"ab",2);
|
||||
|
@ -140,8 +154,8 @@ void uninitvar(int fd) {
|
|||
write(fd,buf,2);
|
||||
// cppcheck-suppress uninitvar
|
||||
write(fd,"ab",x);
|
||||
|
||||
|
||||
|
||||
|
||||
/* int regcomp(regex_t *restrict preg, const char *restrict pattern, int cflags); */
|
||||
regex_t reg;
|
||||
const char * pattern;
|
||||
|
@ -151,12 +165,12 @@ void uninitvar(int fd) {
|
|||
pattern="";
|
||||
// cppcheck-suppress uninitvar
|
||||
regcomp(®, pattern, cflags);
|
||||
regerror (0, ®, 0, 0);
|
||||
regerror(0, ®, 0, 0);
|
||||
// cppcheck-suppress uninitvar
|
||||
// cppcheck-suppress unreadVariable
|
||||
char *buffer = ecvt(d, 11, &decimal, &sign);
|
||||
gcvt(3.141, 2, buf);
|
||||
|
||||
|
||||
char *filename;
|
||||
struct utimbuf *times;
|
||||
// cppcheck-suppress uninitvar
|
||||
|
@ -167,7 +181,8 @@ void uninitvar(int fd) {
|
|||
}
|
||||
|
||||
|
||||
void uninitvar_types(void) {
|
||||
void uninitvar_types(void)
|
||||
{
|
||||
// cppcheck-suppress unassignedVariable
|
||||
blkcnt_t b;
|
||||
// cppcheck-suppress uninitvar
|
||||
|
@ -178,12 +193,13 @@ void uninitvar_types(void) {
|
|||
d.d_ino + 1;
|
||||
}
|
||||
|
||||
void timet_h() {
|
||||
struct timespec* ptp;
|
||||
// cppcheck-suppress uninitvar
|
||||
clock_settime(CLOCK_REALTIME, ptp);
|
||||
|
||||
time_t clock = time(0);
|
||||
char buf[26];
|
||||
ctime_r(&clock, buf);
|
||||
void timet_h()
|
||||
{
|
||||
struct timespec* ptp;
|
||||
// cppcheck-suppress uninitvar
|
||||
clock_settime(CLOCK_REALTIME, ptp);
|
||||
|
||||
time_t clock = time(0);
|
||||
char buf[26];
|
||||
ctime_r(&clock, buf);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ else # assume we are in repo root
|
|||
fi
|
||||
|
||||
# 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
|
||||
CXX=g++
|
||||
|
|
335
test/cfg/std.c
335
test/cfg/std.c
|
@ -12,40 +12,42 @@
|
|||
#include <stdlib.h>
|
||||
#include <tgmath.h> // frexp
|
||||
|
||||
void bufferAccessOutOf(void) {
|
||||
char a[5];
|
||||
fgets(a,5,stdin);
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
fgets(a,6,stdin);
|
||||
sprintf(a, "ab%s", "cd");
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
// cppcheck-suppress redundantCopy
|
||||
sprintf(a, "ab%s", "cde");
|
||||
// cppcheck-suppress redundantCopy
|
||||
snprintf(a, 5, "abcde%i", 1);
|
||||
// cppcheck-suppress redundantCopy
|
||||
snprintf(a, 6, "abcde%i", 1); //TODO: cppcheck-suppress bufferAccessOutOfBounds
|
||||
// cppcheck-suppress redundantCopy
|
||||
strcpy(a,"abcd");
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
// cppcheck-suppress redundantCopy
|
||||
strcpy(a, "abcde");
|
||||
// cppcheck-suppress redundantCopy
|
||||
strncpy(a,"abcde",5);
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
// cppcheck-suppress redundantCopy
|
||||
strncpy(a,"abcde",6);
|
||||
fread(a,1,5,stdin);
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
fread(a,1,6,stdin);
|
||||
fwrite(a,1,5,stdout);
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
fread(a,1,6,stdout);
|
||||
void bufferAccessOutOfBounds(void)
|
||||
{
|
||||
char a[5];
|
||||
fgets(a,5,stdin);
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
fgets(a,6,stdin);
|
||||
sprintf(a, "ab%s", "cd");
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
// cppcheck-suppress redundantCopy
|
||||
sprintf(a, "ab%s", "cde");
|
||||
// cppcheck-suppress redundantCopy
|
||||
snprintf(a, 5, "abcde%i", 1);
|
||||
// cppcheck-suppress redundantCopy
|
||||
snprintf(a, 6, "abcde%i", 1); //TODO: cppcheck-suppress bufferAccessOutOfBounds
|
||||
// cppcheck-suppress redundantCopy
|
||||
strcpy(a,"abcd");
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
// cppcheck-suppress redundantCopy
|
||||
strcpy(a, "abcde");
|
||||
// cppcheck-suppress redundantCopy
|
||||
strncpy(a,"abcde",5);
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
// cppcheck-suppress redundantCopy
|
||||
strncpy(a,"abcde",6);
|
||||
fread(a,1,5,stdin);
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
fread(a,1,6,stdin);
|
||||
fwrite(a,1,5,stdout);
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
fread(a,1,6,stdout);
|
||||
}
|
||||
|
||||
// memory leak
|
||||
|
||||
void ignoreleak(void) {
|
||||
void ignoreleak(void)
|
||||
{
|
||||
char *p = (char *)malloc(10);
|
||||
memset(&(p[0]), 0, 10);
|
||||
// cppcheck-suppress memleak
|
||||
|
@ -53,142 +55,152 @@ void ignoreleak(void) {
|
|||
|
||||
// null pointer
|
||||
|
||||
void nullpointer(int value){
|
||||
int res = 0;
|
||||
FILE *fp;
|
||||
void nullpointer(int value)
|
||||
{
|
||||
int res = 0;
|
||||
FILE *fp;
|
||||
|
||||
// cppcheck-suppress nullPointer
|
||||
clearerr(0);
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress nullPointer
|
||||
feof(0);
|
||||
// cppcheck-suppress nullPointer
|
||||
fgetc(0);
|
||||
// cppcheck-suppress nullPointer
|
||||
fclose(0);
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress nullPointer
|
||||
ferror(0);
|
||||
// cppcheck-suppress nullPointer
|
||||
ftell(0);
|
||||
// cppcheck-suppress nullPointer
|
||||
puts(0);
|
||||
// cppcheck-suppress nullPointer
|
||||
fp=fopen(0,0);
|
||||
fclose(fp); fp = 0;
|
||||
// No FP
|
||||
fflush(0);
|
||||
// No FP
|
||||
// cppcheck-suppress redundantAssignment
|
||||
fp = freopen(0,"abc",stdin);
|
||||
fclose(fp); fp = 0;
|
||||
// cppcheck-suppress nullPointer
|
||||
fputc(0,0);
|
||||
// cppcheck-suppress nullPointer
|
||||
fputs(0,0);
|
||||
// cppcheck-suppress nullPointer
|
||||
fgetpos(0,0);
|
||||
// cppcheck-suppress nullPointer
|
||||
frexp(1.0,0);
|
||||
// cppcheck-suppress nullPointer
|
||||
fsetpos(0,0);
|
||||
// cppcheck-suppress nullPointer
|
||||
itoa(123,0,10);
|
||||
putchar(0);
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress nullPointer
|
||||
strchr(0,0);
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress nullPointer
|
||||
strlen(0);
|
||||
// cppcheck-suppress nullPointer
|
||||
strcpy(0,0);
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress nullPointer
|
||||
strspn(0,0);
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress nullPointer
|
||||
strcspn(0,0);
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress nullPointer
|
||||
strcoll(0,0);
|
||||
// cppcheck-suppress nullPointer
|
||||
strcat(0,0);
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress nullPointer
|
||||
strcmp(0,0);
|
||||
// cppcheck-suppress nullPointer
|
||||
strncpy(0,0,1);
|
||||
// cppcheck-suppress nullPointer
|
||||
strncat(0,0,1);
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress nullPointer
|
||||
strncmp(0,0,1);
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress nullPointer
|
||||
strstr(0,0);
|
||||
// cppcheck-suppress nullPointer
|
||||
strtoul(0,0,0);
|
||||
// cppcheck-suppress nullPointer
|
||||
strtoull(0,0,0);
|
||||
// cppcheck-suppress nullPointer
|
||||
strtol(0,0,0);
|
||||
// cppcheck-suppress nullPointer
|
||||
clearerr(0);
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress nullPointer
|
||||
feof(0);
|
||||
// cppcheck-suppress nullPointer
|
||||
fgetc(0);
|
||||
// cppcheck-suppress nullPointer
|
||||
fclose(0);
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress nullPointer
|
||||
ferror(0);
|
||||
// cppcheck-suppress nullPointer
|
||||
ftell(0);
|
||||
// cppcheck-suppress nullPointer
|
||||
puts(0);
|
||||
// cppcheck-suppress nullPointer
|
||||
fp=fopen(0,0);
|
||||
fclose(fp);
|
||||
fp = 0;
|
||||
// No FP
|
||||
fflush(0);
|
||||
// No FP
|
||||
// cppcheck-suppress redundantAssignment
|
||||
fp = freopen(0,"abc",stdin);
|
||||
fclose(fp);
|
||||
fp = 0;
|
||||
// cppcheck-suppress nullPointer
|
||||
fputc(0,0);
|
||||
// cppcheck-suppress nullPointer
|
||||
fputs(0,0);
|
||||
// cppcheck-suppress nullPointer
|
||||
fgetpos(0,0);
|
||||
// cppcheck-suppress nullPointer
|
||||
frexp(1.0,0);
|
||||
// cppcheck-suppress nullPointer
|
||||
fsetpos(0,0);
|
||||
// cppcheck-suppress nullPointer
|
||||
itoa(123,0,10);
|
||||
putchar(0);
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress nullPointer
|
||||
strchr(0,0);
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress nullPointer
|
||||
strlen(0);
|
||||
// cppcheck-suppress nullPointer
|
||||
strcpy(0,0);
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress nullPointer
|
||||
strspn(0,0);
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress nullPointer
|
||||
strcspn(0,0);
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress nullPointer
|
||||
strcoll(0,0);
|
||||
// cppcheck-suppress nullPointer
|
||||
strcat(0,0);
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress nullPointer
|
||||
strcmp(0,0);
|
||||
// cppcheck-suppress nullPointer
|
||||
strncpy(0,0,1);
|
||||
// cppcheck-suppress nullPointer
|
||||
strncat(0,0,1);
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress nullPointer
|
||||
strncmp(0,0,1);
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress nullPointer
|
||||
strstr(0,0);
|
||||
// cppcheck-suppress nullPointer
|
||||
strtoul(0,0,0);
|
||||
// cppcheck-suppress nullPointer
|
||||
strtoull(0,0,0);
|
||||
// cppcheck-suppress nullPointer
|
||||
strtol(0,0,0);
|
||||
|
||||
// #6100 False positive nullPointer - calling mbstowcs(NULL,)
|
||||
res += mbstowcs(0,"",0);
|
||||
// cppcheck-suppress unreadVariable
|
||||
res += wcstombs(0,L"",0);
|
||||
// #6100 False positive nullPointer - calling mbstowcs(NULL,)
|
||||
res += mbstowcs(0,"",0);
|
||||
// cppcheck-suppress unreadVariable
|
||||
res += wcstombs(0,L"",0);
|
||||
|
||||
strtok(NULL,"xyz");
|
||||
strtok(NULL,"xyz");
|
||||
|
||||
strxfrm(0,"foo",0);
|
||||
// TODO: error message
|
||||
strxfrm(0,"foo",42);
|
||||
|
||||
snprintf(NULL, 0, "someformatstring"); // legal
|
||||
// cppcheck-suppress nullPointer
|
||||
snprintf(NULL, 42, "someformatstring"); // not legal
|
||||
strxfrm(0,"foo",0);
|
||||
// TODO: error message
|
||||
strxfrm(0,"foo",42);
|
||||
|
||||
snprintf(NULL, 0, "someformatstring"); // legal
|
||||
// cppcheck-suppress nullPointer
|
||||
snprintf(NULL, 42, "someformatstring"); // not legal
|
||||
}
|
||||
|
||||
void nullpointerMemchr1(char *p, char *s) {
|
||||
// cppcheck-suppress uselessAssignmentPtrArg
|
||||
p = memchr (s, 'p', strlen(s));
|
||||
void nullpointerMemchr1(char *p, char *s)
|
||||
{
|
||||
// cppcheck-suppress uselessAssignmentPtrArg
|
||||
p = memchr(s, 'p', strlen(s));
|
||||
}
|
||||
|
||||
void nullpointerMemchr2(char *p, char *s) {
|
||||
// cppcheck-suppress uselessAssignmentPtrArg
|
||||
p = memchr (s, 0, strlen(s));
|
||||
void nullpointerMemchr2(char *p, char *s)
|
||||
{
|
||||
// cppcheck-suppress uselessAssignmentPtrArg
|
||||
p = memchr(s, 0, strlen(s));
|
||||
}
|
||||
|
||||
void nullpointerMemchr3(char *p) {
|
||||
char *s = 0;
|
||||
// cppcheck-suppress nullPointer
|
||||
// cppcheck-suppress uselessAssignmentPtrArg
|
||||
p = memchr (s, 0, strlen(s));
|
||||
void nullpointerMemchr3(char *p)
|
||||
{
|
||||
char *s = 0;
|
||||
// cppcheck-suppress nullPointer
|
||||
// cppcheck-suppress uselessAssignmentPtrArg
|
||||
p = memchr(s, 0, strlen(s));
|
||||
}
|
||||
|
||||
void nullpointerMemcmp(char *p) {
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress nullPointer
|
||||
memcmp(p, 0, 123);
|
||||
void nullpointerMemcmp(char *p)
|
||||
{
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress nullPointer
|
||||
memcmp(p, 0, 123);
|
||||
}
|
||||
|
||||
|
||||
// uninit pointers
|
||||
|
||||
void uninit_clearerr(void) {
|
||||
void uninit_clearerr(void)
|
||||
{
|
||||
FILE *fp;
|
||||
// cppcheck-suppress uninitvar
|
||||
clearerr(fp);
|
||||
}
|
||||
|
||||
void uninit_fclose(void) {
|
||||
void uninit_fclose(void)
|
||||
{
|
||||
FILE *fp;
|
||||
// cppcheck-suppress uninitvar
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
void uninit_fopen(void) {
|
||||
void uninit_fopen(void)
|
||||
{
|
||||
const char *filename, *mode;
|
||||
FILE *fp;
|
||||
// cppcheck-suppress uninitvar
|
||||
|
@ -199,33 +211,38 @@ void uninit_fopen(void) {
|
|||
fclose(fp);
|
||||
}
|
||||
|
||||
void uninit_feof(void) {
|
||||
void uninit_feof(void)
|
||||
{
|
||||
FILE *fp;
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress uninitvar
|
||||
feof(fp);
|
||||
}
|
||||
|
||||
void uninit_ferror(void) {
|
||||
void uninit_ferror(void)
|
||||
{
|
||||
FILE *fp;
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
// cppcheck-suppress uninitvar
|
||||
ferror(fp);
|
||||
}
|
||||
|
||||
void uninit_fflush(void) {
|
||||
void uninit_fflush(void)
|
||||
{
|
||||
FILE *fp;
|
||||
// cppcheck-suppress uninitvar
|
||||
fflush(fp);
|
||||
}
|
||||
|
||||
void uninit_fgetc(void) {
|
||||
void uninit_fgetc(void)
|
||||
{
|
||||
FILE *fp;
|
||||
// cppcheck-suppress uninitvar
|
||||
fgetc(fp);
|
||||
}
|
||||
|
||||
void uninit_fgetpos(void) {
|
||||
void uninit_fgetpos(void)
|
||||
{
|
||||
FILE *fp;
|
||||
fpos_t pos;
|
||||
fpos_t *ppos;
|
||||
|
@ -238,7 +255,8 @@ void uninit_fgetpos(void) {
|
|||
fclose(fp);
|
||||
}
|
||||
|
||||
void uninit_fsetpos(void) {
|
||||
void uninit_fsetpos(void)
|
||||
{
|
||||
FILE *fp;
|
||||
fpos_t pos;
|
||||
fpos_t *ppos;
|
||||
|
@ -251,7 +269,8 @@ void uninit_fsetpos(void) {
|
|||
fclose(fp);
|
||||
}
|
||||
|
||||
void uninit_fgets(void) {
|
||||
void uninit_fgets(void)
|
||||
{
|
||||
FILE *fp;
|
||||
char buf[10];
|
||||
char *str;
|
||||
|
@ -265,7 +284,8 @@ void uninit_fgets(void) {
|
|||
fgets(buf,10,fp);
|
||||
}
|
||||
|
||||
void uninit_fputc(void) {
|
||||
void uninit_fputc(void)
|
||||
{
|
||||
int i;
|
||||
FILE *fp;
|
||||
|
||||
|
@ -278,7 +298,8 @@ void uninit_fputc(void) {
|
|||
fputc('a', fp);
|
||||
}
|
||||
|
||||
void uninit_fputs(void) {
|
||||
void uninit_fputs(void)
|
||||
{
|
||||
const char *s;
|
||||
FILE *fp;
|
||||
|
||||
|
@ -291,26 +312,30 @@ void uninit_fputs(void) {
|
|||
fputs("a", fp);
|
||||
}
|
||||
|
||||
void uninit_ftell(void) {
|
||||
void uninit_ftell(void)
|
||||
{
|
||||
FILE *fp;
|
||||
// cppcheck-suppress uninitvar
|
||||
ftell(fp);
|
||||
}
|
||||
|
||||
void uninit_puts(void) {
|
||||
void uninit_puts(void)
|
||||
{
|
||||
const char *s;
|
||||
// cppcheck-suppress uninitvar
|
||||
puts(s);
|
||||
}
|
||||
|
||||
void uninit_putchar(void) {
|
||||
void uninit_putchar(void)
|
||||
{
|
||||
char c;
|
||||
// cppcheck-suppress uninitvar
|
||||
putchar(c);
|
||||
}
|
||||
|
||||
void ignoreretrn(void) {
|
||||
char szNumbers[] = "2001 60c0c0 -1101110100110100100000 0x6fffff";
|
||||
char * pEnd;
|
||||
strtol (szNumbers,&pEnd,10);
|
||||
void ignoreretrn(void)
|
||||
{
|
||||
char szNumbers[] = "2001 60c0c0 -1101110100110100100000 0x6fffff";
|
||||
char * pEnd;
|
||||
strtol(szNumbers,&pEnd,10);
|
||||
}
|
||||
|
|
|
@ -10,16 +10,52 @@
|
|||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <cctype>
|
||||
|
||||
void bufferAccessOutOf(void) {
|
||||
char a[5];
|
||||
std::strcpy(a,"abcd");
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
// cppcheck-suppress redundantCopy
|
||||
std::strcpy(a, "abcde");
|
||||
// cppcheck-suppress redundantCopy
|
||||
std::strncpy(a,"abcde",5);
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
// cppcheck-suppress redundantCopy
|
||||
std::strncpy(a,"abcde",6);
|
||||
void bufferAccessOutOfBounds(void)
|
||||
{
|
||||
char a[5];
|
||||
std::strcpy(a,"abcd");
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
// cppcheck-suppress redundantCopy
|
||||
std::strcpy(a, "abcde");
|
||||
// cppcheck-suppress redundantCopy
|
||||
std::strncpy(a,"abcde",5);
|
||||
// cppcheck-suppress bufferAccessOutOfBounds
|
||||
// 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);
|
||||
}
|
||||
|
|
|
@ -7,12 +7,13 @@
|
|||
//
|
||||
|
||||
class CSharedFilesCtrl {
|
||||
void OpenFile(const CShareableFile* file, int, int);
|
||||
afx_msg void OnNmDblClk(NMHDR *pNMHDR, LRESULT *pResult);
|
||||
void OpenFile(const CShareableFile* file, int, int);
|
||||
afx_msg void OnNmDblClk(NMHDR *pNMHDR, LRESULT *pResult);
|
||||
|
||||
};
|
||||
|
||||
void CSharedFilesCtrl::OnNmDblClk(NMHDR* /*pNMHDR*/, LRESULT* pResult) {
|
||||
if (file)
|
||||
OpenFile(file,0,0); // <- not the windows OpenFile function
|
||||
void CSharedFilesCtrl::OnNmDblClk(NMHDR* /*pNMHDR*/, LRESULT* pResult)
|
||||
{
|
||||
if (file)
|
||||
OpenFile(file,0,0); // <- not the windows OpenFile function
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue