You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
What is the behavior of malloc with size zero? #1277
but the docs for malloc do not state anything about its behavior if the size is 0.
I suppose that it follows the C11 standard, that is, from 7.20.3.1:
If the size of the space requested is zero, the behavior is implementation defined:
either a null pointer is returned, or the behavior is as if the size were some
nonzero value, except that the returned pointer shall not be used to access an object.
Since jemalloc is the implementation, it should defined the behavior, either to one of the two behaviors allowed, or to both (that is, stating that any of both allowed behaviors could happen).
Activity
gnzlbg commentedon Jul 12, 2018
Note: the docs of free say:
so this might indicate that
mallocbehavior whensizeis0is to returnNULL.rustyx commentedon Sep 1, 2018
je_malloc(0)essentially behaves the same asje_malloc(1):So it is conforming.
Though spelling out this exact behavior in the manual will lead to people relying on it when they shouldn't.