[LLVMbugs] [Bug 10795] New: Extend memset-like sizeof() checks to	*alloc
    bugzilla-daemon at llvm.org 
    bugzilla-daemon at llvm.org
       
    Sat Aug 27 16:08:52 PDT 2011
    
    
  
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: unassignedclangbugs at nondot.org
        ReportedBy: joerg at NetBSD.org
                CC: llvmbugs at cs.uiuc.edu
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.
    
    
More information about the llvm-bugs
mailing list