[PATCH] D76830: [Analyzer][MallocChecker] No warning for kfree of ZERO_SIZE_PTR.

Balázs Kéri via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 26 02:07:54 PDT 2020


balazske created this revision.
Herald added subscribers: cfe-commits, ASDenysPetrov, martong, Charusso, gamesh411, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
Herald added a reviewer: Szelethus.
Herald added a project: clang.
balazske added a comment.
balazske marked an inline comment as done.

FIXME: There is a test file "kmalloc-linux.c" but it seems to be non-maintained and buggy (has no //-verify// option so it passes always but produces multiple warnings).



================
Comment at: clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp:146
 
   return IntValue.getSExtValue();
 }
----------------
The function was changed to get the numeric value from the end of the macro in any case. This way it recognizes a `(void *)16` as 16 (but maybe `16+16` too as 16).


The kernel kmalloc function may return a constant value ZERO_SIZE_PTR
if a zero-sized block is allocated. This special value is allowed to
be passed to kfree and should produce no warning.

This is a simple version but should be no problem. The macro is always
detected independent of if this is a kernel source code or any other
code. And it is recognized in any kind of free function, not only kfree.
(These functions are used already intermixed, at least in the tests.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76830

Files:
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
  clang/test/Analysis/kmalloc-linux-1.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76830.252769.patch
Type: text/x-patch
Size: 4057 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200326/950d67a4/attachment-0001.bin>


More information about the cfe-commits mailing list