Merge branch 'master' of git@github.com:danmar/cppcheck

This commit is contained in:
Vesa Pikki 2009-05-23 14:26:40 +03:00
commit 31a88bd0ba
2 changed files with 31 additions and 1 deletions

View File

@ -214,7 +214,9 @@ const char * CheckMemoryLeakClass::call_func(const Token *tok, std::list<const T
return 0;
// I/O functions that are not allocating nor deallocating memory..
if (Token::Match(tok, "fgets|fgetc|fputs|fputc|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;
// Convert functions that are not allocating nor deallocating memory..

View File

@ -216,6 +216,7 @@ private:
TEST_CASE(strndup_function);
TEST_CASE(fcloseall_function);
TEST_CASE(file_functions);
TEST_CASE(pointer_to_pointer);
}
@ -2189,6 +2190,33 @@ private:
ASSERT_EQUALS(std::string(""), errout.str());
}
void file_functions()
{
check("void f()\n"
"{\n"
"FILE *f = fopen(fname, str);\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");
ASSERT_EQUALS(std::string("[test.cpp:22]: (error) Resource leak: f\n"), errout.str());
}
void pointer_to_pointer()
{
check("void f(char **data)\n"