Library: Renamed <ignore> to <leak-ignore>

This commit is contained in:
Daniel Marjamäki 2013-07-20 13:12:24 +02:00
parent 9c67af058a
commit be5e4ccfd5
6 changed files with 26 additions and 15 deletions

View File

@ -18,7 +18,10 @@
<use>g_register_data</use> <use>g_register_data</use>
</memory> </memory>
<ignore>g_strcmp</ignore> <function name="g_strcmp">
<leak-ignore/>
<noreturn>false</noreturn>
</function>
<function name="g_exit"> <function name="g_exit">
<noreturn>true</noreturn> <noreturn>true</noreturn>

View File

@ -345,7 +345,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
if (dealloc == NOALLOC && Token::simpleMatch(tok, ") ; }")) { if (dealloc == NOALLOC && Token::simpleMatch(tok, ") ; }")) {
const std::string &functionName(tok->link()->previous()->str()); const std::string &functionName(tok->link()->previous()->str());
bool unknown = false; bool unknown = false;
if (_settings->library.ignore.find(functionName) == _settings->library.ignore.end() && if (_settings->library.leakignore.find(functionName) == _settings->library.leakignore.end() &&
_settings->library.use.find(functionName) == _settings->library.use.end() && _settings->library.use.find(functionName) == _settings->library.use.end() &&
_tokenizer->IsScopeNoReturn(tok->tokAt(2), &unknown)) { _tokenizer->IsScopeNoReturn(tok->tokAt(2), &unknown)) {
if (unknown) { if (unknown) {
@ -385,7 +385,7 @@ void CheckLeakAutoVar::functionCall(const Token *tok, VarInfo *varInfo, const in
std::map<unsigned int, std::string> &possibleUsage = varInfo->possibleUsage; std::map<unsigned int, std::string> &possibleUsage = varInfo->possibleUsage;
// Ignore function call? // Ignore function call?
const bool ignore = bool(_settings->library.ignore.find(tok->str()) != _settings->library.ignore.end()); const bool ignore = bool(_settings->library.leakignore.find(tok->str()) != _settings->library.leakignore.end());
if (ignore) if (ignore)
return; return;

View File

@ -570,7 +570,7 @@ bool CheckMemoryLeakInFunction::test_white_list(const std::string &funcname)
const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<const Token *> callstack, const unsigned int varid, AllocType &alloctype, AllocType &dealloctype, bool &allocpar, 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 &allocpar, unsigned int sz)
{ {
if (test_white_list(tok->str()) || if (test_white_list(tok->str()) ||
(_settings->library.ignore.find(tok->str()) != _settings->library.ignore.end())) { (_settings->library.leakignore.find(tok->str()) != _settings->library.leakignore.end())) {
if (tok->str() == "asprintf" || if (tok->str() == "asprintf" ||
tok->str() == "delete" || tok->str() == "delete" ||
tok->str() == "fclose" || tok->str() == "fclose" ||

View File

@ -106,8 +106,6 @@ bool Library::load(const char exename[], const char path[])
} }
} }
else if (strcmp(node->Name(),"ignore")==0)
ignore.insert(node->GetText());
else if (strcmp(node->Name(),"function")==0) { else if (strcmp(node->Name(),"function")==0) {
const char *name = node->Attribute("name"); const char *name = node->Attribute("name");
if (name == NULL) if (name == NULL)
@ -116,6 +114,8 @@ bool Library::load(const char exename[], const char path[])
for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) { for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
if (strcmp(functionnode->Name(),"noreturn")==0) if (strcmp(functionnode->Name(),"noreturn")==0)
_noreturn[name] = (strcmp(functionnode->GetText(), "true") == 0); _noreturn[name] = (strcmp(functionnode->GetText(), "true") == 0);
else if (strcmp(functionnode->Name(),"leak-ignore")==0)
leakignore.insert(name);
else if (strcmp(functionnode->Name(),"arg")==0 && functionnode->Attribute("nr") != NULL) { else if (strcmp(functionnode->Name(),"arg")==0 && functionnode->Attribute("nr") != NULL) {
const int nr = atoi(functionnode->Attribute("nr")); const int nr = atoi(functionnode->Attribute("nr"));
bool notnull = false; bool notnull = false;

View File

@ -59,7 +59,7 @@ public:
} }
std::set<std::string> use; std::set<std::string> use;
std::set<std::string> ignore; std::set<std::string> leakignore;
bool isnoreturn(const std::string &name) const { bool isnoreturn(const std::string &name) const {
std::map<std::string,bool>::const_iterator it = _noreturn.find(name); std::map<std::string,bool>::const_iterator it = _noreturn.find(name);

View File

@ -753,7 +753,9 @@ Checking test.c...
&lt;dealloc&gt;Unlock&lt;/dealloc&gt; &lt;dealloc&gt;Unlock&lt;/dealloc&gt;
&lt;/resource&gt; &lt;/resource&gt;
&lt;ignore&gt;IsEqual&lt;/ignore&gt; &lt;function name="IsEqual"&gt;
&lt;leak-ignore/&gt;
&lt;/function&gt;
&lt;function name="AssignFred"&gt; &lt;function name="AssignFred"&gt;
&lt;noreturn&gt;false&lt;/noreturn&gt; &lt;noreturn&gt;false&lt;/noreturn&gt;
@ -776,10 +778,10 @@ Checking test.c...
<literal>CloseWilma</literal>.</para> <literal>CloseWilma</literal>.</para>
<para>The <literal>&lt;use&gt;</literal> and <para>The <literal>&lt;use&gt;</literal> and
<literal>&lt;ignore&gt;</literal> elements are used to control the leaks <literal>&lt;leak-ignore&gt;</literal> elements are used to control the
checking. If it should be ignored that a function is called, use leaks checking. If it should be ignored that a function is called, use
<literal>&lt;ignore&gt;</literal>. If there is no leak whenever the memory <literal>&lt;leak-ignore&gt;</literal>. If there is no leak whenever the
is passed to a function, use <literal>&lt;use&gt;</literal>.</para> memory is passed to a function, use <literal>&lt;use&gt;</literal>.</para>
<para>In the <literal>&lt;function&gt;</literal> block some useful info is <para>In the <literal>&lt;function&gt;</literal> block some useful info is
added about function behaviour. The <literal>&lt;noreturn&gt;</literal> added about function behaviour. The <literal>&lt;noreturn&gt;</literal>
@ -797,12 +799,13 @@ Checking test.c...
<para>No configuration is necessary for the standard functions. The <para>No configuration is necessary for the standard functions. The
strcpy() was chosen in this example for demonstration purposes because strcpy() was chosen in this example for demonstration purposes because
its behaviour is well-known. </para> its behaviour is well-known.</para>
<para>The proper configuration for the standard strcpy() function would <para>The proper configuration for the standard strcpy() function would
be:</para> be:</para>
<programlisting> &lt;function name="strcpy"&gt; <programlisting> &lt;function name="strcpy"&gt;
&lt;leak-ignore/&gt;
&lt;noreturn&gt;false&lt;/noreturn&gt; &lt;noreturn&gt;false&lt;/noreturn&gt;
&lt;arg nr="1"&gt; &lt;arg nr="1"&gt;
&lt;not-null/&gt; &lt;not-null/&gt;
@ -813,17 +816,22 @@ Checking test.c...
&lt;/arg&gt; &lt;/arg&gt;
&lt;/function&gt;</programlisting> &lt;/function&gt;</programlisting>
<para>The <literal>&lt;leak-ignore/&gt;</literal> is optional and it
tells Cppcheck to ignore this function call in the leaks checking.
Passing allocated memory to this function won't mean it will be
deallocated.</para>
<para>The <literal>&lt;noreturn&gt;</literal> is optional. But it's <para>The <literal>&lt;noreturn&gt;</literal> is optional. But it's
recommended.</para> recommended.</para>
<para>The first parameter that the function takes is a pointer. It must <para>The first argument that the function takes is a pointer. It must
not be a null pointer, a uninitialized pointer nor a dead pointer. It not be a null pointer, a uninitialized pointer nor a dead pointer. It
must point at some data, this data can be initialized but it is not must point at some data, this data can be initialized but it is not
wrong if it isn't. Using <literal>&lt;not-null&gt;</literal> is correct. wrong if it isn't. Using <literal>&lt;not-null&gt;</literal> is correct.
<literal>Cppcheck</literal> will check by default that the pointer is <literal>Cppcheck</literal> will check by default that the pointer is
not uninitialized nor dead.</para> not uninitialized nor dead.</para>
<para>The second parameter the function takes is a pointer. It must not <para>The second argument the function takes is a pointer. It must not
be null. And it must point at initialized data. Using be null. And it must point at initialized data. Using
<literal>&lt;not-null&gt;</literal> and <literal>&lt;not-null&gt;</literal> and
<literal>&lt;not-uninit&gt;</literal> is correct.</para> <literal>&lt;not-uninit&gt;</literal> is correct.</para>