In https://www.openwall.com/lists/oss-security/2024/07/26/1 I commented:
"Note that asprintf() and vasprintf() are part of the POSIX.1-2024 standard which was officially published last month, so these are no longer system-specific extensions:
https://pubs.opengroup.org/onlinepubs/9799919799/functions/asprintf.html
https://pubs.opengroup.org/onlinepubs/9799919799/functions/vasprintf.html
though they are not yet part of the C standard itself."
To ask the #POSIX committee to add them, I just had to submit https://austingroupbugs.net/view.php?id=1496
I wish it was that easy to ask the C committee, instead of having to write a paper for it.
As @solardiz noted in the followup post at https://www.openwall.com/lists/oss-security/2024/07/26/2 the standard unfortunately allowed the GNU libc behavior of not guaranteeing the pointer would be NULL on failure, requiring users to check the return value, despite all the known non-GNU implementations guaranteeing to set it to NULL on failure, meaning that even though the standard requires asprintf() be provided, portable software still has to be aware of the different implementations.
@lanodan certainly the GNU libc maintainers could add attribute(warn_unused_result) to the asprintf prototype in their header files if they want to insist on this.
@alanc Right, always forget about attributes, too used to using standards as sole target and documentation.
At least C23 (yet to be released) should add [[nodiscard]]
.