[Bug c/55791] gcc fails to detect wrong type in sizeof in malloc
egallager at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Dec 24 18:49:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55791
--- Comment #4 from Eric Gallager <egallager at gcc dot gnu.org> ---
For reference, clang catches this with its static analyzer:
$ clang --analyze 55791.c
55791.c:10:15: warning: Result of 'malloc' is converted to a pointer of type
'char', which is incompatible with sizeof operand type 'char *'
p = (char *) malloc( 10 * sizeof( char *));
~~~~~~ ^~~~~~ ~~~~~~~~~~~~~~~
1 warning generated.
$
Since gcc will be getting a static analyzer, too, once David Malcolm's analyzer
branch is merged, we could do this warning there, but I think it would make
more sense to do this warning in the compiler proper, though.
More information about the Gcc-bugs
mailing list