Repository navigation
Conversation
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
The fix works for the reported case (#11023) and for variants such as delete c, delete[] (c) and delete[] (c+1). True positives where the data is read (delete c[0], delete[] *c, delete s->p, an uninitialized pointer) are still reported. One new false negative: the check skips every delete of a non-dereferenced pointer, so it no longer warns when the destructor of the deleted type reads members that were never initialized (struct V { int x; ~V(){ if (x) {} } }; V* v = new V; delete v;). Base reported that case. I found no false positives or crashes.
Comments
| # | Comment | By | Where | Status |
|---|---|---|---|---|
| 1 | delete of a class whose destructor reads uninitialized members is no longer reported | AI review | lib/checkuninitvar.cpp:1257 |
🆕 New (false negative) |
@danmar, please fix, resolve or reply to the open and new comments: #1.
For #1 (false negative), it is enough to create a Trac ticket and link it here. It does not need to be fixed in this PR.
Testing
Built cppcheck and testrunner in pr/, and cppcheck in base/; both builds succeeded. ./testrunner TestUninitVar: 70 tests, 0 failed.
I compared base and PR on scratch files with cppcheck -q --enable=all --inconclusive:
- False positive gone:
new char[12]; delete[] c;,new char; delete c;,delete[] (c);anddelete[] (c+1);. - Still reported, as in base:
delete c[0],delete[] *c,delete s->p, a read ofc[0]or*cbefore the delete, and an uninitialized pointer passed to delete.
New false negative:
struct U { int x; ~U(); };
void g1() { U* u = new U; delete u; }
struct V { int x; ~V() { if (x) {} } };
void g2() { V* v = new V; delete v; }
void g3() { V* v = new V[2]; delete [] v; }cppcheck -q --enable=warning b.cpp
- base:
uninitdataon lines 2, 4 and 5 - PR: no output
Not run: the full test suite and the Python tests in test/cli (the PR doesn't touch them).
Automated review of 775bfe3 by Claude. The pull request was built and tested locally.
| if (Token::simpleMatch(valueExpr->astParent(), "return")) | ||
| return nullptr; | ||
| // deallocating the memory does not read the data | ||
| if (!derefValue && Token::simpleMatch(valueExpr->astParent(), "delete")) |
There was a problem hiding this comment.
AI review
This returns nullptr for every delete p where p is not dereferenced, whatever the pointed-to type is. For a class with a user-written destructor that reads members, the delete does read the uninitialized data:
struct V { int x; ~V() { if (x) {} } };
void g2() { V* v = new V; delete v; }
void g3() { V* v = new V[2]; delete [] v; }Base reports uninitdata for both functions; the PR reports nothing. One option is to skip only when the pointed-to type is trivially destructible, i.e. it is not a class with a user-declared destructor. A test for this case would also help.
|
Test results for commit 775bfe3 (tools/test-my-pr.py, main compared to this PR): Test: http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-9089/ 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. |
No description provided.