This change clarifies the message provided when the analyzer catches the use of memory that is allocated with size zero.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp | ||
---|---|---|
2474–2476 | Peanut gallery says: |
Yuck I forgot to forge commit author. Sorry!!
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp | ||
---|---|---|
2474–2476 | 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. |
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).