Skip to content

CheckLeakAutoVar: --check-library accepts <use> functions - #8953

Open
pduchi wants to merge 1 commit into
cppcheck-opensource:mainfrom
pduchi:checkleakautovar-use-silences-check-library
Open

pduchi wants to merge 1 commit into
cppcheck-opensource:mainfrom
pduchi:checkleakautovar-use-silences-check-library

Conversation

@pduchi

@pduchi pduchi commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

I don't have a Trac account, so there is no ticket for this; the details are below. Feel free to create one and I'll add it to the title.

Passing an allocated pointer to a function configured as <use> still gives a --check-library message:

use.cfg:

<memory>
  <alloc>myalloc</alloc>
  <use>set_data</use>
  <dealloc>myfree</dealloc>
</memory>
<function name="myalloc"><noreturn>false</noreturn><arg nr="1"/></function>
<function name="set_data"><noreturn>false</noreturn><arg nr="1"/></function>

use.c:

void f(void)
{
    char *p = myalloc(10);
    set_data(p);
}

$ cppcheck --check-library --library=use.cfg use.c
use.c:5:1: warning: --check-library: Function set_data() should have <use>/<leak-ignore> configuration [checkLibraryUseIgnore]

The cfg reference says <use> exists to silence exactly this message, but CheckLeakAutoVarImpl::configurationInfo() only took <leak-ignore/> into account. It now skips functions that have <use> as well. The leak analysis itself is unchanged.

Test: TestLeakAutoVar::configurationUse; it fails without the change.

Passing an allocated pointer to a function configured as <use> still gave
  --check-library: Function f() should have <use>/<leak-ignore> configuration
The reference says <use> is there to silence exactly that message, so do
not report functions that have it.
@dmcppcheck

Copy link
Copy Markdown

There should probably be a trac ticket for this PR. Please create it, or ask us to create it. Then the PR title should be updated.

@dmcppcheck dmcppcheck left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review

I found no new problems. With the PR, --check-library stops reporting checkLibraryUseIgnore for functions configured as <use>, both at the end of the scope and on early-return paths. That is what man/reference-cfg-format.md says <use> is for. The leak analysis itself gives the same results as before. The only earlier comment, which asks for a Trac ticket, is still open.

Testing

  • I built cppcheck and testrunner in pr/, and cppcheck in base/.
  • ./testrunner TestLeakAutoVar TestLeakAutoVarStrcpy TestLeakAutoVarRecursiveCountLimit TestLeakAutoVarWindows TestLeakAutoVarPosix: 161 tests ran, 0 failed. This includes the new configurationUse test.
  • Scratch tests. I wrote a custom cfg with <use> entries in a <memory> group (set_data, ns::take) and in a <resource> group (rsetup), then ran cppcheck --check-library --enable=information from PR and base on these cases:
    • Simple case: p is passed to set_data(p). The base reports checkLibraryUseIgnore; the PR does not.
    • Qualified name: passing p to ns::take(p) also gives the message in base and not in the PR.
    • Resource handle: passing an int handle to rsetup(fd) behaves the same way.
    • Early return: with if (set_data(p)) { return; }, base gives two messages (one per path) and the PR gives none.
    • Order of calls: for set_data(p); g(p);, both versions still report g() as needing configuration. For g(p); set_data(p);, neither version reports g(), because the later call already overwrote the possible usage in base.
    • Real leak: set_data(p + 1) gets the same memleak error in both versions.
  • Real cfg file: I ran cppcheck with the options from test/cfg/runtests.sh on test/cfg/gtk.c with --library=gtk, which uses many <use> entries. PR and base gave identical output.
  • No file in test/cfg or test/cli mentions checkLibraryUseIgnore, so no inline suppression there becomes unmatched.
  • I did not run the Python tests in test/cli, because the PR does not touch them.

Automated review of 1301cc4 by Claude. The pull request was built and tested locally.

@pduchi

pduchi commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

There should probably be a trac ticket for this PR. Please create it, or ask us to create it. Then the PR title should be updated.

Can you create one for me? I send you a private msg ( danielmarjamaki ) in the meantime for getting access to trac with a htpasswd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants