[PATCH] malloc: Remove redundant NULL check
Wilco Dijkstra
Wilco.Dijkstra@arm.com
Wed Jul 30 09:57:09 GMT 2025
Hi Cupertino,
> I wonder if in glibc there is an assert macro we could use to better
> protect this code from programmer mistakes.
> Can we add asserts in malloc code ?
assert() is used but it's broken in that those asserts are not removed in
release builds. So we need to fix that before we add asserts in hot paths.
> When revisiting this code, all I can think of is, let me set an assert
> to protect 'e' from ever being NULL.
>
> The only reason this does not seg faults is that we only call this
> function if the bin has at least one element. Well, this check is never
> verified within the function context, making it very fragile from a
> software engineering point of view.
Well if you deference 'e' unconditionally immediately after assigning it
then that is evidence that it cannot ever be NULL!
Cheers,
Wilco
More information about the Libc-alpha
mailing list