[Bug c/79696] missing -Wunused-result on calls to malloc() and calloc()
egallager at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Oct 31 04:09:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79696
Eric Gallager <egallager at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pinskia at gcc dot gnu.org
--- Comment #5 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> -Wunused-result warns on the attribute warn_unused_result usage. If these
> functions are not marked that way in glibc, it is maybe a glibc bug.
> I don't think we should mark these as warn_unused_result really.
GNU Coding Standards say to always check the result of malloc() and realloc()
in the "Writing Robust Programs" section:
https://www.gnu.org/prep/standards/html_node/Semantics.html#Semantics
(this is why xmalloc and xrealloc are used instead in libiberty and gnulib and
everywhere)
Based on this, I think it makes sense to mark them as warn_unused_result.
(on a tangential note, I think it'd make sense to add a -Wgcs flag that warns
about all the checkable coding guidelines mentioned in the GNU Coding
Standards)
More information about the Gcc-bugs
mailing list