From 47a1332e6a33813302c8898307c2a3491d543527 Mon Sep 17 00:00:00 2001 From: Ettl Martin Date: Tue, 19 Apr 2011 16:55:27 +0200 Subject: [PATCH] #2733 added sizeof to checkmemory-leaks white list, added a todo-testcase --- lib/checkmemoryleak.cpp | 2 +- test/testmemleak.cpp | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 5d0df311d..23ee7c192 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -66,7 +66,7 @@ static const char * const call_func_white_list[] = , "readlink", "readv" , "realloc", "regcomp", "remove", "rename", "return", "rewind", "rewinddir", "rindex" , "rmdir" ,"scandir", "scanf", "seekdir" - , "setbuf", "setbuffer", "sethostname", "setlinebuf", "setlocale" ,"setvbuf", "snprintf", "sprintf", "sscanf" + , "setbuf", "setbuffer", "sethostname", "setlinebuf", "setlocale" ,"setvbuf", "sizeof" ,"snprintf", "sprintf", "sscanf" , "stat", "stpcpy", "strcasecmp", "strcat", "strchr", "strcmp", "strcoll" , "strcpy", "strcspn", "strdup", "stricmp", "strlen", "strncasecmp", "strncat", "strncmp" , "strncpy", "strpbrk","strrchr", "strspn", "strstr", "strtod", "strtol", "strtoul", "strxfrm", "switch" diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 9a96d942c..1cfedc84d 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -232,6 +232,7 @@ private: TEST_CASE(func22); // Ticket #2668 TEST_CASE(func23); // Ticket #2667 TEST_CASE(func24); // Ticket #2705 + TEST_CASE(func25); // Ticket #2733 TEST_CASE(allocfunc1); TEST_CASE(allocfunc2); @@ -589,7 +590,7 @@ private: , "getservbyname", "getservbyport", "glob", "index", "inet_addr", "inet_aton", "inet_network" , "initgroups", "link", "mblen", "mbstowcs", "mbtowc", "mkdir", "mkfifo", "mknod", "obstack_printf" , "obstack_vprintf", "opendir", "parse_printf_format", "pathconf", "popen", "psignal", "putenv" - , "readlink", "regcomp", "strxfrm", "wordexp" + , "readlink", "regcomp", "strxfrm", "wordexp", "sizeof" }; for (unsigned int i = 0; i < (sizeof(call_func_white_list) / sizeof(char *)); ++i) @@ -2199,6 +2200,31 @@ private: ASSERT_EQUALS("", errout.str()); } + // #2733 + void func25() + { + check("int* GetDeviceName(int a, int b)\n" + "{\n" + " int *p = new int[255];\n" + " memset(p, 0, 255 * sizeof(int));\n" + " if(a)\n" + " if(b)\n" + " return p;\n" + " return NULL; \n" + "}\n"); + TODO_ASSERT_EQUALS("[test.cpp:8]: (error) Memory leak: p\n","", errout.str()); + + check("int* GetDeviceName(int a)\n" + "{\n" + " int *p = new int[255];\n" + " memset(p, 0, 255 * sizeof(int));\n" + " if(a)\n" + " return p;\n" + " return NULL; \n" + "}\n"); + ASSERT_EQUALS("[test.cpp:7]: (error) Memory leak: p\n", errout.str()); + } + void allocfunc1() { check("static char *a()\n"