Library: Renamed <ignore> to <leak-ignore>
This commit is contained in:
parent
9c67af058a
commit
be5e4ccfd5
|
@ -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>
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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" ||
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -753,7 +753,9 @@ Checking test.c...
|
||||||
<dealloc>Unlock</dealloc>
|
<dealloc>Unlock</dealloc>
|
||||||
</resource>
|
</resource>
|
||||||
|
|
||||||
<ignore>IsEqual</ignore>
|
<function name="IsEqual">
|
||||||
|
<leak-ignore/>
|
||||||
|
</function>
|
||||||
|
|
||||||
<function name="AssignFred">
|
<function name="AssignFred">
|
||||||
<noreturn>false</noreturn>
|
<noreturn>false</noreturn>
|
||||||
|
@ -776,10 +778,10 @@ Checking test.c...
|
||||||
<literal>CloseWilma</literal>.</para>
|
<literal>CloseWilma</literal>.</para>
|
||||||
|
|
||||||
<para>The <literal><use></literal> and
|
<para>The <literal><use></literal> and
|
||||||
<literal><ignore></literal> elements are used to control the leaks
|
<literal><leak-ignore></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><ignore></literal>. If there is no leak whenever the memory
|
<literal><leak-ignore></literal>. If there is no leak whenever the
|
||||||
is passed to a function, use <literal><use></literal>.</para>
|
memory is passed to a function, use <literal><use></literal>.</para>
|
||||||
|
|
||||||
<para>In the <literal><function></literal> block some useful info is
|
<para>In the <literal><function></literal> block some useful info is
|
||||||
added about function behaviour. The <literal><noreturn></literal>
|
added about function behaviour. The <literal><noreturn></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> <function name="strcpy">
|
<programlisting> <function name="strcpy">
|
||||||
|
<leak-ignore/>
|
||||||
<noreturn>false</noreturn>
|
<noreturn>false</noreturn>
|
||||||
<arg nr="1">
|
<arg nr="1">
|
||||||
<not-null/>
|
<not-null/>
|
||||||
|
@ -813,17 +816,22 @@ Checking test.c...
|
||||||
</arg>
|
</arg>
|
||||||
</function></programlisting>
|
</function></programlisting>
|
||||||
|
|
||||||
|
<para>The <literal><leak-ignore/></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><noreturn></literal> is optional. But it's
|
<para>The <literal><noreturn></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><not-null></literal> is correct.
|
wrong if it isn't. Using <literal><not-null></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><not-null></literal> and
|
<literal><not-null></literal> and
|
||||||
<literal><not-uninit></literal> is correct.</para>
|
<literal><not-uninit></literal> is correct.</para>
|
||||||
|
|
Loading…
Reference in New Issue