Skip to content

Fix #15212 (FN ctunullpointer through a wrapper function with --cppcheck-build-dir) - #9024

Open
g-chauvel wants to merge 1 commit into
cppcheck-opensource:mainfrom
g-chauvel:ctu-nested-call
Open

g-chauvel wants to merge 1 commit into
cppcheck-opensource:mainfrom
g-chauvel:ctu-nested-call

Conversation

@g-chauvel

Copy link
Copy Markdown
Contributor

NestedCall::toXmlString() writes a <function-call> element but loadFromXml() only reads nested calls from <nested-call> elements. So the nested calls are dropped when the CTU info is read back from the build dir: with -j2 and more, with -j1 as soon as one of the files is unchanged, and in the GUI. A null pointer passed through a wrapper function is then not reported.

header.h

void wrapper(int *p);

test1.c

#include "header.h"
int g;
void deref(int *p) { g = *p; }
void wrapper(int *p) { deref(p); }

test2.c

#include "header.h"
void f(void) { wrapper(0); }
mkdir bd
cppcheck -q --template=simple -j2 --cppcheck-build-dir=bd test1.c test2.c

Before PR: no output.

After PR:

test1.c:3:27: error: Null pointer dereference: p [ctunullpointer]

…eck-build-dir)

Write nested calls as nested-call elements in the CTU info.
loadFromXml() only reads nested calls from nested-call elements, so a
call chain through a wrapper function was lost when the whole program
analysis loads the build dir data: with -j2 and more, with -j1 as soon as one
of the files is unchanged, and in the GUI.

@dmcppcheck dmcppcheck left a comment

Copy link
Copy Markdown
Contributor

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 problems. The fix is correct. NestedCall::toXmlString() now writes <nested-call>, which is the name CTU::FileInfo::loadFromXml() expects, and its tag stays self-closing. Old analyzer-info files that hold the wrong <function-call> elements don't need special handling. Before the fix, those elements failed FunctionCall::loadFromXml because call-argexpr and related attributes were missing, so they were just dropped. On top of that, the cache hash includes the cppcheck version, so old files are not reused after an upgrade. The only other reader of function-call is test/cli/other_test.py:4648, which reads FileInfo/function-call/path and is not affected. I have no new problems to report.

Testing

  • I built cppcheck and testrunner in pr/ without errors.

  • ./testrunner TestNullPointer TestUninitVar TestBufferOverrun TestCppcheck TestAnalyzerInformation: 433 tests, 0 failed. This includes the new ctuXml test.

  • pytest whole-program_test.py: 30 passed, 6 xfailed. This includes the 3 new tests.

  • pytest other_test.py -k "analyzerinfo or ctu or nested or build": 17 passed, 1 xfailed.

  • I wrote my own test with wrapper chains across two files, run with --enable=warning:

    • a two-level wrapper (w1 -> mid -> deref)
    • conditional wrappers
    • a guarded wrapper (if (p) deref(p))
    • ctuuninitvar through a wrapper
    • ctuArrayIndex through a wrapper

    I ran it three ways: without a build dir, with -j2 --cppcheck-build-dir, and with -j1 against the cached build dir. All three gave the same output: ctunullpointer, ctuuninitvar and ctuArrayIndex, with no false positive for the guarded wrapper.

  • I also tried mutual recursion across files (a -> b -> a) with and without a build dir. Neither hung, and both gave the same (empty) result.

  • I did not build base/. In the PR build, results with a build dir now match results without one.


Automated review of 872dbb3 by Claude. The pull request was built and tested locally.

@dmcppcheck

Copy link
Copy Markdown
Contributor

Test results for commit 872dbb3 (tools/test-my-pr.py, main compared to this PR):

Test: http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-9024/
packages: 100
Differing warnings: 0 (+0 -0)
Timing: -0.2% (http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-9024/2026-11-13_12-53-07-872dbb3aedd6_timing.html)

Posted automatically by the cppcheck PR test runner. +N: warnings only with this PR, -N: warnings only with main. The AI review is written by Claude and can be wrong.

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