XORG_CHECK_MALLOC_ZERO: stop testing malloc, assume the worst

tlaronde at kergis.com tlaronde at kergis.com
Fri Oct 25 10:47:54 UTC 2024


On Thu, Oct 24, 2024 at 03:14:01PM -0700, Alan Coopersmith wrote:
> After a recent conversation on Mastodon about how checking if a malloc()
> implementation returns NULL for malloc(0) at build time can give different
> answers than you may get at runtime if an application or LD_PRELOAD has
> interposed a different malloc implementation, I wrote a patch to our
> autoconf macros to stop checking and instead always assume we need to
> handle that case:
> 
> https://gitlab.freedesktop.org/xorg/util/macros/-/merge_requests/9
> 
> It's been sitting in gitlab for 2 weeks without comment - I figured I'd
> give a larger audience a chance to chime in before I go ahead and merge
> it - but if I don't hear anything soon, I'll do just that.
> 
> (Mainly this makes code like libX11 define malloc wrapper macros such as:
> # define Xmalloc(size) malloc((size_t)((size) == 0 ? 1 : (size)))
> which the compiler can hopefully optimize down to a simple malloc(size)
> for most calls when the value is known to be non-zero at compile time.)
FW my opinion is worth, this seems reasonable since whatever is tested
by autoconf might not be what is indeed in place on the installed host
(not to mention that some malloc implementation allow to change
behavior via environment variables...).

-- 
        Thierry Laronde <tlaronde +AT+ kergis +dot+ com>
                     http://www.kergis.com/
                    http://kertex.kergis.com/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C


More information about the xorg-devel mailing list