#2659 added stat function to white list and provide unit tests.

This commit is contained in:
Ettl Martin 2011-03-20 22:17:51 +01:00
parent ab6888dbfe
commit 7afc0978c2
2 changed files with 49 additions and 2 deletions

View File

@ -56,7 +56,7 @@ static const char * const call_func_white_list[] =
, "posix_fadvise", "posix_fallocate", "pread"
, "printf", "puts", "pwrite", "qsort", "read", "readahead", "readdir", "readdir_r", "readv"
, "realloc", "return", "rewind", "rewinddir", "scandir", "scanf", "seekdir"
, "setbuf", "setbuffer", "setlinebuf", "setvbuf", "snprintf", "sprintf", "sscanf", "strcasecmp"
, "setbuf", "setbuffer", "setlinebuf", "setvbuf", "snprintf", "sprintf", "sscanf", "stat", "strcasecmp"
, "strcat", "strchr", "strcmp", "strcpy", "stricmp", "strlen", "strncat", "strncmp"
, "strncpy", "strrchr", "strstr", "strtod", "strtol", "strtoul", "switch"
, "sync_file_range", "telldir", "time", "typeid", "vfprintf", "vprintf"

View File

@ -576,7 +576,7 @@ private:
, "setbuf", "setbuffer", "setlinebuf", "setvbuf", "snprintf", "sprintf", "strcasecmp"
, "strcat", "strchr", "strcmp", "strcpy", "stricmp", "strlen", "strncat", "strncmp"
, "strncpy", "strrchr", "strstr", "strtod", "strtol", "strtoul", "switch"
, "sync_file_range", "telldir", "typeid", "while", "write", "writev", "lstat"
, "sync_file_range", "telldir", "typeid", "while", "write", "writev", "lstat", "stat"
};
for (unsigned int i = 0; i < (sizeof(call_func_white_list) / sizeof(char *)); ++i)
@ -1735,6 +1735,8 @@ private:
//# Ticket 2569
void func21()
{
// checking for lstat function:
// ----------------------------
check("void foo ()\n"
"{\n"
" struct stat CFileAttr;\n"
@ -1776,6 +1778,51 @@ private:
" return;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
/// checking for stat function:
// ----------------------------
check("void foo ()\n"
"{\n"
" struct stat CFileAttr;\n"
" char *cpFile = new char [13];\n"
" strcpy (cpFile, \"testfile.txt\");\n"
" if ( stat (cpFile, &CFileAttr) != 0)\n"
" {\n"
" return;\n"
" }\n"
" return;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:10]: (error) Memory leak: cpFile\n", errout.str());
check("void foo ()\n"
"{\n"
" struct stat CFileAttr;\n"
" char *cpFile = new char [13];\n"
" strcpy (cpFile, \"testfile.txt\");\n"
" if ( stat (cpFile, &CFileAttr) != 0)\n"
" {\n"
" delete [] cpFile;\n"
" return;\n"
" }\n"
" return;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:11]: (error) Memory leak: cpFile\n", errout.str());
check("void foo ()\n"
"{\n"
" struct stat CFileAttr;\n"
" char *cpFile = new char [13];\n"
" strcpy (cpFile, \"testfile.txt\");\n"
" if ( stat (cpFile, &CFileAttr) != 0)\n"
" {\n"
" delete [] cpFile;\n"
" return;\n"
" }\n"
" delete [] cpFile;\n"
" return;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void allocfunc1()