https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78902
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |msebor at gcc dot gnu.org --- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> --- Warning on malloc with an unused return value sounds like a good idea to me (in fact, it seems that all allocation functions to be declared with warn_unused_result; i.e., all those declared with attribute alloc_size). I also think warning on malloc(0) can be useful. GCC 7 has -Walloc-zero that warns on all zero-size allocations. Unfortunately, it's not in -Wall or -Wextra and has to be explicitly enabled. Unconditionally turning malloc(0) into NULL wouldn't be safe since the call is allowed to return a unique non-null pointer and there are implementations (e.g., Glibc) that do return one. But doing that under an option might be useful on targets where the system malloc returns null (though it could break with superimposition). I'm not sure that eliminating calls to malloc whose return value is unused is a safe optimization. Malloc can be superimposed and the replacement version might have important side-effects that the optimization would prevent.