http://llvm.org/bugs/show_bug.cgi?id=10795

           Summary: Extend memset-like sizeof() checks to *alloc
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
        AssignedTo: [email protected]
        ReportedBy: [email protected]
                CC: [email protected]


It would be nice if malloc and friends had type-based diagnostic like memset:

foo = malloc(sizeof(bar))

should check whether:

(1) typeof(foo) == typeof(bar) --> warning

(2) sizeof(bar) < sizeof(foo) --> warning

foo = (bar *)malloc(...)

should additionally check that typeof(foo) == bar * and recomment removing the
cast. This is pre-ANSI style.

A static analyzer for expressions of the form malloc(x * sizeof(y)) etc might
be useful if x can't be proven to be small enough to not trigger overflow.

A static analyzer check for the following idiom would be nice:

foo = malloc(len);
memset(foo, 0, len);

--> foo = calloc(1, len);

foo = malloc(x * sizeof(**foo));
memset(foo, 0, x * sizeof(**foo));

--> foo = calloc(x, sizeof(**foo));

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to