[cfe-dev] [ MallocSizeofChecker ] - False positive about MallocSizeofChecker

Wong Henry via cfe-dev cfe-dev at lists.llvm.org
Sun Sep 3 20:23:10 PDT 2017


Hi all,
I encountered a false positive when using the MallocSizeofChecker, but I am not sure whether it can be called false positives.
Given the below code sippet:
---------------------------------------------------------------
unsigned int *ptr = NULL;
ptr = (unsigned int*)malloc(sizeof(int) * 12);
---------------------------------------------------------------
The analyzer ouput:
    warning: Result of 'malloc' is converted to a pointer of type 'unsigned int', which is incompatible with sizeof operand type 'int'
            ptr = (unsigned int*)malloc(sizeof(int) * 12);
               ~~~~~~~~~~~~~ ^~~~~~ ~~~~~~~~~~~
As 'signed int' and 'unsigned int' occupies the same amount of storage and has the same alignment requirements, I don't think it should emit a warning here.
I'd like to ask is this a false positive?

Thanks,
Henry Wong.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170904/6b4fbb1b/attachment.html>


More information about the cfe-dev mailing list