AW: XORG_CHECK_MALLOC_ZERO: stop testing malloc, assume the worst

Walter Harms wharms at bfs.de
Tue Oct 29 11:29:37 UTC 2024


hello,
if i rember correctly there is a whole wrapper for malloc in libX11.

Beside that i would suggest something like
EXPECTED_GLIBC_BEHAVIER (default)
or you are on your own otherwise you start to fix a bunch of errors in these wrappers.
ppl that use LD_PRELOAD simply should know what they are doing.

How often may malloc(0) occur ? glibc says it will return a valid pointer, i thing that reasonable and easy to check.

ym2c


________________________________________
Von: xorg-devel <xorg-devel-bounces at lists.x.org> im Auftrag von Alan Coopersmith <alan.coopersmith at oracle.com>
Gesendet: Freitag, 25. Oktober 2024 00:14
An: X.Org Development
Betreff: XORG_CHECK_MALLOC_ZERO: stop testing malloc, assume the worst

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.)

--
         -Alan Coopersmith-                 alan.coopersmith at oracle.com
          Oracle Solaris Engineering - https://blogs.oracle.com/solaris



More information about the xorg-devel mailing list