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] Add reallocarray function.


On 11.04.2017 09:55, Florian Weimer wrote:
> On 04/10/2017 05:00 PM, Dennis Wölfing wrote:
>> +void *
>> +__libc_reallocarray(void *optr, size_t nmemb, size_t elem_size)
>> +{
>> +  INTERNAL_SIZE_T bytes;
>> +  if (check_mul_overflow(nmemb, elem_size, &bytes))
>> +    {
>> +      __set_errno (ENOMEM);
>> +      return 0;
>> +    }
>> +  else
>> +    return __libc_realloc (optr, bytes);
>> +}
> 
> This needs to go into its own file and has to call realloc (not
> __libc_realloc), otherwise it will not be compatible with malloc
> interposition.

Ok, I see the problem. When a statically linked program defines their
own memory allocation functions, calls to reallocarray pull in malloc.c
and thus cause link errors.

The static inline function check_mul_overflow is used in both
reallocarray and calloc. So that function would need to be in a file
that can be included by both malloc.c and a new reallocarray.c file.

Would malloc-internal.h be a good location to put that inline function
or should I place it into its own separate file?


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