This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


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] xdr_array and calloc security fix


> Why not 2^32? size_t is unsigned.

Yes, however malloc can only handle chunks of a little less than 2^31
currently, so the _int_malloc later will fail anyway...  But that is
ok, having a power of two as the compared value wins against this
micro-optimisation:

> So you mean something like:
>   bytes = n * elem_size;
>   if (__builtin_expect ((a | b) >= 65536, 0)) {
>     if (bytes / elem_size != n) {
>       MALLOC_FAILURE_ACTION;
>       return 0;
>     }
>   }

Hey, nice, avoids the second comparision and ||.  Looks like we have a
winner?

Regards,
Wolfram.


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