From ff3a1714f292d1bc495112dd83f7fa1f61f9aea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 13 Dec 2008 19:07:29 +0000 Subject: [PATCH] Memory leak : added standard functions that are safe and doesn't need to be checked --- CheckMemoryLeak.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/CheckMemoryLeak.cpp b/CheckMemoryLeak.cpp index 532cfce8c..b58253270 100644 --- a/CheckMemoryLeak.cpp +++ b/CheckMemoryLeak.cpp @@ -189,9 +189,26 @@ CheckMemoryLeakClass::AllocType CheckMemoryLeakClass::GetDeallocationType( const //-------------------------------------------------------------------------- const char * CheckMemoryLeakClass::call_func( const TOKEN *tok, std::list callstack, const char *varnames[], AllocType &alloctype, AllocType &dealloctype ) -{ - if (TOKEN::Match(tok,"if") || TOKEN::Match(tok,"for") || TOKEN::Match(tok,"while")) +{ + // Keywords that are not function calls.. + if (TOKEN::Match(tok,"if|for|while")) + return 0; + + // String functions that are not allocating nor deallocating memory.. + if (TOKEN::Match(tok, "strcpy|strncpy|strcat|strncat|strcmp|strncmp|strcasecmp|stricmp|sprintf|strchr|strrchr|strstr")) + return 0; + + // Memory functions that are not allocating nor deallocating memory.. + if (TOKEN::Match(tok, "memset|memcpy|memmove|memchr")) + return 0; + + // I/O functions that are not allocating nor deallocating memory.. + if (TOKEN::Match(tok, "fgets|fgetc|fputs|fputc|printf")) return 0; + + // Convert functions that are not allocating nor deallocating memory.. + if (TOKEN::Match(tok, "atoi|atof|atol|strtol|strtoul|strtod")) + return 0; if (GetAllocationType(tok)!=No || GetReallocationType(tok)!=No || GetDeallocationType(tok,varnames)!=No) return 0;