[LLVMbugs] [Bug 14526] New: freebsd kernel malloc with M_ZERO

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Dec 6 11:54:11 PST 2012


             Bug #: 14526
           Summary: freebsd kernel malloc with M_ZERO
           Product: clang
           Version: 3.1
          Platform: PC
        OS/Version: FreeBSD
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
        AssignedTo: kremenek at apple.com
        ReportedBy: shivaram.u at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

The FreeBSD kernel malloc takes an additional parameter M_ZERO which zeros the
memory on successful allocation. But clang isn't aware of this. For example the
below test case 

struct test {

#define M_ZERO  1
extern void *malloc(int size, int flags);

static void*
zalloc(int size)
        return malloc(size, M_ZERO);

void bar(int count)
        struct test **testlist, *test;
        int i;

        testlist = zalloc(count);
        if (!testlist)

        for (i = 0; i < count; i++) {
                test = testlist[i];

Results in

zalloc.c:24:8: warning: Assigned value is garbage or undefined
                test = testlist[i];
                     ^ ~~~~~~~~~~~
1 warning generated.

NOTE: Built with -fno-builtin passed to gcc as would be the case with the
kernel/kernel module build

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