On the Effectiveness of nonnull: Difference between revisions

Created page with "'''dankblog! 2021-11-05, 0236 EDT, at the danktower''' I add <code>nonnull</code> [https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html anno..."
 
No edit summary
Line 57: Line 57:
</syntaxhighlight>
</syntaxhighlight>


OH SHIT, THERE GOES THE PLANET. that error check is completely pointless; indeed, the compiler might well elide it entirely (if <tt>buf</tt> is <tt>NULL</tt>, dereferencing it in the <tt>memdup</tt> line is undefined behavior, and the compiler can do whatever it wants. if it is not <tt>NULL</tt>, the check is pointless. thus work the mysterious minds of the compiler people). a static analyzer arguably ought have picked up on this (and i run several analyzers regularly), but there's good reasons why not, also.
OH SHIT, THERE GOES THE PLANET. that error check is completely pointless; indeed, the compiler might well elide it entirely (if <tt>buf</tt> is <tt>NULL</tt>, dereferencing it in the <tt>memdup</tt> line is undefined behavior, and the compiler can do whatever it wants. if it is not <tt>NULL</tt>, the check is pointless. thus work the mysterious minds of the Compiler People). a static analyzer arguably ought have picked up on this (and i run several analyzers regularly), but there's good reasons why not, also.


either way, adding <tt>nonnull(2)</tt> immediately generated the warning:
either way, adding <tt>nonnull(2)</tt> immediately generated the warning: