Skip to content

Commit be5e4cc

Browse files
committed
Library: Renamed <ignore> to <leak-ignore>
1 parent 9c67af0 commit be5e4cc

6 files changed

Lines changed: 26 additions & 15 deletions

File tree

cfg/gtk.cfg

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
<use>g_register_data</use>
1919
</memory>
2020

21-
<ignore>g_strcmp</ignore>
21+
<function name="g_strcmp">
22+
<leak-ignore/>
23+
<noreturn>false</noreturn>
24+
</function>
2225

2326
<function name="g_exit">
2427
<noreturn>true</noreturn>

lib/checkleakautovar.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
345345
if (dealloc == NOALLOC && Token::simpleMatch(tok, ") ; }")) {
346346
const std::string &functionName(tok->link()->previous()->str());
347347
bool unknown = false;
348-
if (_settings->library.ignore.find(functionName) == _settings->library.ignore.end() &&
348+
if (_settings->library.leakignore.find(functionName) == _settings->library.leakignore.end() &&
349349
_settings->library.use.find(functionName) == _settings->library.use.end() &&
350350
_tokenizer->IsScopeNoReturn(tok->tokAt(2), &unknown)) {
351351
if (unknown) {
@@ -385,7 +385,7 @@ void CheckLeakAutoVar::functionCall(const Token *tok, VarInfo *varInfo, const in
385385
std::map<unsigned int, std::string> &possibleUsage = varInfo->possibleUsage;
386386

387387
// Ignore function call?
388-
const bool ignore = bool(_settings->library.ignore.find(tok->str()) != _settings->library.ignore.end());
388+
const bool ignore = bool(_settings->library.leakignore.find(tok->str()) != _settings->library.leakignore.end());
389389

390390
if (ignore)
391391
return;

lib/checkmemoryleak.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ bool CheckMemoryLeakInFunction::test_white_list(const std::string &funcname)
570570
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)
571571
{
572572
if (test_white_list(tok->str()) ||
573-
(_settings->library.ignore.find(tok->str()) != _settings->library.ignore.end())) {
573+
(_settings->library.leakignore.find(tok->str()) != _settings->library.leakignore.end())) {
574574
if (tok->str() == "asprintf" ||
575575
tok->str() == "delete" ||
576576
tok->str() == "fclose" ||

lib/library.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ bool Library::load(const char exename[], const char path[])
106106
}
107107
}
108108

109-
else if (strcmp(node->Name(),"ignore")==0)
110-
ignore.insert(node->GetText());
111109
else if (strcmp(node->Name(),"function")==0) {
112110
const char *name = node->Attribute("name");
113111
if (name == NULL)
@@ -116,6 +114,8 @@ bool Library::load(const char exename[], const char path[])
116114
for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) {
117115
if (strcmp(functionnode->Name(),"noreturn")==0)
118116
_noreturn[name] = (strcmp(functionnode->GetText(), "true") == 0);
117+
else if (strcmp(functionnode->Name(),"leak-ignore")==0)
118+
leakignore.insert(name);
119119
else if (strcmp(functionnode->Name(),"arg")==0 && functionnode->Attribute("nr") != NULL) {
120120
const int nr = atoi(functionnode->Attribute("nr"));
121121
bool notnull = false;

lib/library.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class CPPCHECKLIB Library {
5959
}
6060

6161
std::set<std::string> use;
62-
std::set<std::string> ignore;
62+
std::set<std::string> leakignore;
6363

6464
bool isnoreturn(const std::string &name) const {
6565
std::map<std::string,bool>::const_iterator it = _noreturn.find(name);

man/manual.docbook

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,9 @@ Checking test.c...
753753
&lt;dealloc&gt;Unlock&lt;/dealloc&gt;
754754
&lt;/resource&gt;
755755

756-
&lt;ignore&gt;IsEqual&lt;/ignore&gt;
756+
&lt;function name="IsEqual"&gt;
757+
&lt;leak-ignore/&gt;
758+
&lt;/function&gt;
757759

758760
&lt;function name="AssignFred"&gt;
759761
&lt;noreturn&gt;false&lt;/noreturn&gt;
@@ -776,10 +778,10 @@ Checking test.c...
776778
<literal>CloseWilma</literal>.</para>
777779

778780
<para>The <literal>&lt;use&gt;</literal> and
779-
<literal>&lt;ignore&gt;</literal> elements are used to control the leaks
780-
checking. If it should be ignored that a function is called, use
781-
<literal>&lt;ignore&gt;</literal>. If there is no leak whenever the memory
782-
is passed to a function, use <literal>&lt;use&gt;</literal>.</para>
781+
<literal>&lt;leak-ignore&gt;</literal> elements are used to control the
782+
leaks checking. If it should be ignored that a function is called, use
783+
<literal>&lt;leak-ignore&gt;</literal>. If there is no leak whenever the
784+
memory is passed to a function, use <literal>&lt;use&gt;</literal>.</para>
783785

784786
<para>In the <literal>&lt;function&gt;</literal> block some useful info is
785787
added about function behaviour. The <literal>&lt;noreturn&gt;</literal>
@@ -797,12 +799,13 @@ Checking test.c...
797799

798800
<para>No configuration is necessary for the standard functions. The
799801
strcpy() was chosen in this example for demonstration purposes because
800-
its behaviour is well-known. </para>
802+
its behaviour is well-known.</para>
801803

802804
<para>The proper configuration for the standard strcpy() function would
803805
be:</para>
804806

805807
<programlisting> &lt;function name="strcpy"&gt;
808+
&lt;leak-ignore/&gt;
806809
&lt;noreturn&gt;false&lt;/noreturn&gt;
807810
&lt;arg nr="1"&gt;
808811
&lt;not-null/&gt;
@@ -813,17 +816,22 @@ Checking test.c...
813816
&lt;/arg&gt;
814817
&lt;/function&gt;</programlisting>
815818

819+
<para>The <literal>&lt;leak-ignore/&gt;</literal> is optional and it
820+
tells Cppcheck to ignore this function call in the leaks checking.
821+
Passing allocated memory to this function won't mean it will be
822+
deallocated.</para>
823+
816824
<para>The <literal>&lt;noreturn&gt;</literal> is optional. But it's
817825
recommended.</para>
818826

819-
<para>The first parameter that the function takes is a pointer. It must
827+
<para>The first argument that the function takes is a pointer. It must
820828
not be a null pointer, a uninitialized pointer nor a dead pointer. It
821829
must point at some data, this data can be initialized but it is not
822830
wrong if it isn't. Using <literal>&lt;not-null&gt;</literal> is correct.
823831
<literal>Cppcheck</literal> will check by default that the pointer is
824832
not uninitialized nor dead.</para>
825833

826-
<para>The second parameter the function takes is a pointer. It must not
834+
<para>The second argument the function takes is a pointer. It must not
827835
be null. And it must point at initialized data. Using
828836
<literal>&lt;not-null&gt;</literal> and
829837
<literal>&lt;not-uninit&gt;</literal> is correct.</para>

0 commit comments

Comments
 (0)