Fixed #1266 ('qsort' missing in call_func_white_list)

This commit is contained in:
Daniel Marjamäki 2010-01-18 21:34:11 +01:00
parent 53d036fadf
commit 32604dd55e
3 changed files with 39 additions and 5 deletions

View File

@ -48,7 +48,7 @@ static const char * const call_func_white_list[] =
, "fseeko", "fsetpos", "fstat", "fsync", "ftell", "ftello", "ftruncate" , "fseeko", "fsetpos", "fstat", "fsync", "ftell", "ftello", "ftruncate"
, "fwrite", "getc", "if", "ioctl", "lockf", "lseek", "memchr", "memcpy" , "fwrite", "getc", "if", "ioctl", "lockf", "lseek", "memchr", "memcpy"
, "memmove", "memset", "posix_fadvise", "posix_fallocate", "pread" , "memmove", "memset", "posix_fadvise", "posix_fallocate", "pread"
, "printf", "puts", "pwrite", "read", "readahead", "readdir", "readdir_r", "readv" , "printf", "puts", "pwrite", "qsort", "read", "readahead", "readdir", "readdir_r", "readv"
, "realloc", "return", "rewind", "rewinddir", "scandir", "seekdir" , "realloc", "return", "rewind", "rewinddir", "scandir", "seekdir"
, "setbuf", "setbuffer", "setlinebuf", "setvbuf", "snprintf", "sprintf", "strcasecmp" , "setbuf", "setbuffer", "setlinebuf", "setvbuf", "snprintf", "sprintf", "strcasecmp"
, "strcat", "strchr", "strcmp", "strcpy", "stricmp", "strlen", "strncat", "strncmp" , "strcat", "strchr", "strcmp", "strcpy", "stricmp", "strlen", "strncat", "strncmp"
@ -517,11 +517,16 @@ static int countParameters(const Token *tok)
return -1; return -1;
} }
bool CheckMemoryLeakInFunction::test_white_list(const char funcname[])
{
return std::bsearch(funcname, call_func_white_list,
sizeof(call_func_white_list) / sizeof(call_func_white_list[0]),
sizeof(call_func_white_list[0]), call_func_white_list_compare);
}
const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<const Token *> callstack, const unsigned int varid, AllocType &alloctype, AllocType &dealloctype, bool &all, unsigned int sz) const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<const Token *> callstack, const unsigned int varid, AllocType &alloctype, AllocType &dealloctype, bool &all, unsigned int sz)
{ {
if (std::bsearch(tok->strAt(0), call_func_white_list, if (test_white_list(tok->strAt(0)))
sizeof(call_func_white_list) / sizeof(call_func_white_list[0]),
sizeof(call_func_white_list[0]), call_func_white_list_compare))
return 0; return 0;
if (noreturn.find(tok->str()) != noreturn.end()) if (noreturn.find(tok->str()) != noreturn.end())

View File

@ -159,6 +159,9 @@ public:
checkMemoryLeak.check(); checkMemoryLeak.check();
} }
/** For unit testing the white list */
static bool test_white_list(const char funcname[]);
void check(); void check();
void localleaks(); void localleaks();

View File

@ -206,7 +206,8 @@ private:
// Check that getcode works correctly.. // Check that getcode works correctly..
TEST_CASE(testgetcode); TEST_CASE(testgetcode);
// Todo: check that call_func works correctly.. // check that call_func works correctly..
TEST_CASE(call_func);
// Check that simplifycode works correctly.. // Check that simplifycode works correctly..
TEST_CASE(simplifycode); TEST_CASE(simplifycode);
@ -505,6 +506,31 @@ private:
} }
void call_func()
{
// whitelist..
ASSERT_EQUALS(true, CheckMemoryLeakInFunction::test_white_list("qsort"));
static const char * const call_func_white_list[] =
{
"asprintf", "atof", "atoi", "atol", "clearerr", "delete", "fchmod", "fcntl"
, "fdatasync", "feof", "ferror", "fflush", "fgetc", "fgetpos", "fgets"
, "flock", "for", "fprintf", "fputc", "fputs", "fread", "free", "fscanf", "fseek"
, "fseeko", "fsetpos", "fstat", "fsync", "ftell", "ftello", "ftruncate"
, "fwrite", "getc", "if", "ioctl", "lockf", "lseek", "memchr", "memcpy"
, "memmove", "memset", "posix_fadvise", "posix_fallocate", "pread"
, "printf", "puts", "pwrite", "read", "readahead", "readdir", "readdir_r", "readv"
, "realloc", "return", "rewind", "rewinddir", "scandir", "seekdir"
, "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"
};
for (unsigned int i = 0; i < (sizeof(call_func_white_list) / sizeof(char *)); ++i)
ASSERT_EQUALS(true, CheckMemoryLeakInFunction::test_white_list(call_func_white_list[i]));
}
std::string simplifycode(const char code[], bool &all) const std::string simplifycode(const char code[], bool &all) const
{ {