[PATCH] D111655: [analyzer] non-obvious analyzer warning: Use of zero-allocated memory
Artem Dergachev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 12 11:29:11 PDT 2021
NoQ added a comment.
Yuck I forgot to forge commit author. Sorry!!
================
Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:2474-2475
auto R = std::make_unique<PathSensitiveBugReport>(
- *BT_UseZerroAllocated[*CheckKind], "Use of zero-allocated memory", N);
+ *BT_UseZerroAllocated[*CheckKind],
+ "Use of memory allocated with size zero", N);
----------------
Quuxplusone wrote:
> Peanut gallery says:
> (1) Might want to fix the typo in "Zerro" at the same time, or in a followup commit.
> (2) I would naively have expected all the test cases below to give something simple like "Read/write beyond end of allocated space," because they allocate N bytes and then try to read/write into byte number N. This is //never// allowed in C or C++, regardless of the value of N; there's nothing special about N=0. So I don't see why it needs //any// special diagnostic (confusing or otherwise).
The only thing special about N=0 is that the static analyzer is currently better at catching it. It's much easier to catch correctly and avoid false positives when *any* use is disallowed than when some uses are allowed but some aren't.
Speaking of typos, it probably also makes sense to fix the bug type message ("Use of zero allocated") to include a subject.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D111655/new/
https://reviews.llvm.org/D111655
More information about the cfe-commits
mailing list