[PATCH] make analyzer track memory allocated by if_nameindex

Anna Zaks ganna at apple.com
Wed Oct 1 18:00:27 PDT 2014


+    MOK_None,
Do we need this one?

+    if (Family == AF_Malloc && CheckFree) {
+    if (Family == AF_Malloc && CheckAlloc) {

A possible micro optimization would be to check the family once for the common two cases. Also, note that "ChecksEnabled[CK_MallocOptimistic]" most commonly evaluates to false.
if (Family == AF_Malloc) {
    if (CheckFree) {
      if ()       ...
    } else {
      assert(CheckAlloc); 
      if ()       ...
    }
    if (!ChecksEnabled[CK_MallocOptimistic])
      return false;
}

Do you have commit access?

Thanks!
Anna.

> On Oct 1, 2014, at 3:09 PM, Daniel Fahlgren <daniel at fahlgren.se> wrote:
> 
> Hi Anna,
> 
> On ons, 2014-09-24 at 10:02 -0700, Anna Zaks wrote:
>> How about the similar functions from the malloc family:
>> isAllocationFunction and isFreeFunction?
>> 
>> You could either introduce a helper function which checks if the
>> FunctionDecl declares a function from the given list of identifiers or
>> introduce a function that takes FunctionDecl, ASTContext, familyKind,
>> and MemoryOperationKind (enum class MemoryOperationKind { MOK_Allocate,
>> MOK_Free };) and checks if the FunctionDecl belongs to that family and
>> memory operation. (The second approach is probably better.)
> 
> Yes, the second approach does sound better. Combining the four functions
> into one required a bit if thinking in order to maintain readability.
> Attached is a patch that refactors isAllocationFunction and
> isFreeFunction, as well as adding support for if_*nameindex functions.
> 
> Any comments?
> 
> Cheers,
> Daniel
> <ifnameindex.patch>




More information about the cfe-commits mailing list