This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Refactor malloc (x * sizeof (t) to XNMALLOC (x, t).


KOSAKI Motohiro wrote:
>>    inline void *
>>    nmalloc (size_t n, size_t s)
>>    {
>>      return malloc (n <= SIZE_MAX / s ? n * s : SIZE_MAX);
> 
> I'm worry about this. Rounding down to SIZE_DOWN is sometime dangerous.
> How about return NULL instead?

This code assumes that malloc (SIZE_MAX) returns NULL,
which is a safe assumption with glibc.  If glibc were
changed so that malloc (SIZE_MAX) could return non-NULL,
then indeed nmalloc would have to return NULL (and set errno)
when the arguments are out of range.  I assume that
the above code is more efficient (though this should
probably be measured....).


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]