[llvm-bugs] [Bug 50214] New: unix.MallocSizeof false positive

via llvm-bugs llvm-bugs at lists.llvm.org
Tue May 4 03:03:16 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=50214

            Bug ID: 50214
           Summary: unix.MallocSizeof false positive
           Product: clang
           Version: 11.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: dcoughlin at apple.com
          Reporter: orgads at gmail.com
                CC: dcoughlin at apple.com, llvm-bugs at lists.llvm.org

test.c:
#include <stdlib.h>

struct Foo { int member; };

int main() {
  void **foo = (void **)malloc(sizeof(struct Foo *));
  free(foo);
}

$ scan-build gcc test.c
scan-build: Using '/usr/lib/llvm-11/bin/clang' for static analysis
test.c:6:25: warning: Result of 'malloc' is converted to a pointer of type
'void *', which is incompatible with sizeof operand type 'struct Foo *'
[unix.MallocSizeof]
  void **foo = (void **)malloc(sizeof(struct Foo *));
  ~~~~~~~               ^~~~~~ ~~~~~~~~~~~~~~~~~~~~

sizeof is the same for all pointer types.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210504/5d821e2f/attachment.html>


More information about the llvm-bugs mailing list