Added 17 functions which work with FILE structure to white list.

Inspired by previous commit.
This commit is contained in:
Slava Semushin 2009-05-23 18:01:18 +07:00
parent b5c7316666
commit bfd49e21e7
2 changed files with 23 additions and 4 deletions

View File

@ -214,7 +214,9 @@ const char * CheckMemoryLeakClass::call_func(const Token *tok, std::list<const T
return 0; return 0;
// I/O functions that are not allocating nor deallocating memory.. // I/O functions that are not allocating nor deallocating memory..
if (Token::Match(tok, "fgets|fgetc|fputs|fputc|feof|printf")) if (Token::Match(tok, "fgets|fgetc|fputs|fputc|feof|ferror|clearerr|printf|fprintf") ||
Token::Match(tok, "fread|fwrite|fflush|fseek|fseeko|ftell|ftello|fsetpos|fgetpos") ||
Token::Match(tok, "setvbuf|setbuf|setbuffer|setlinebuf|rewind"))
return 0; return 0;
// Convert functions that are not allocating nor deallocating memory.. // Convert functions that are not allocating nor deallocating memory..

View File

@ -216,7 +216,7 @@ private:
TEST_CASE(strndup_function); TEST_CASE(strndup_function);
TEST_CASE(fcloseall_function); TEST_CASE(fcloseall_function);
TEST_CASE(feof_function); TEST_CASE(file_functions);
TEST_CASE(pointer_to_pointer); TEST_CASE(pointer_to_pointer);
} }
@ -2190,14 +2190,31 @@ private:
ASSERT_EQUALS(std::string(""), errout.str()); ASSERT_EQUALS(std::string(""), errout.str());
} }
void feof_function() void file_functions()
{ {
check("void f()\n" check("void f()\n"
"{\n" "{\n"
"FILE *f = fopen(fname, str);\n" "FILE *f = fopen(fname, str);\n"
"feof(f);\n" "feof(f);\n"
"clearerr(in);\n"
"ferror(in);\n"
"fread(ptr, 10, 1, in);\n"
"fwrite(ptr, 10, 1, in);\n"
"fflush(in);\n"
"setbuf(in, buf);\n"
"setbuffer(in, buf, 100);\n"
"setlinebuf(in);\n"
"setvbuf(in, buf, _IOLBF, 0);\n"
"fseek(in, 10, SEEK_SET);\n"
"fseeko(in, 10, SEEK_SET);\n"
"ftell(in);\n"
"ftello(in);\n"
"rewind(in);\n"
"fsetpos(in, 0);\n"
"fgetpos(in, 10);\n"
"fprintf(in, \"text\\n\");\n"
"}\n"); "}\n");
ASSERT_EQUALS(std::string("[test.cpp:5]: (error) Resource leak: f\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:22]: (error) Resource leak: f\n"), errout.str());
} }
void pointer_to_pointer() void pointer_to_pointer()