[PATCH] Fix dereference of possible nullptr in -O3

John Baldwin jhb@FreeBSD.org
Tue May 10 17:32:04 GMT 2022


On 5/10/22 7:09 AM, Simon Farre via Gdb-patches wrote:
> Building with full optimizations (-O3) complains that this might
> be a nullptr. If this is never null, perhaps the parameter
> should be changed to a reference, but that would change the interface.

The pointer should never be null and it would be a bug to invoke this
function with it set to null.  Note that out_regcache is also
referenced a few lines earlier in the previous else-if clause without
a check.  If we were to add the proposed check we would need to add
one there as well.  I think though that we would rather have the
incorrect API usage result in a crash rather than continuing with
behavior not expected by the caller.

-- 
John Baldwin


More information about the Gdb-patches mailing list