This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib 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]

Problems with malloc(LARGEINT) How to fix?


I've just noticed that malloc becomes confused when given an argument
that is near the maximum for an unsigned int.

An attempt is made to round up the number of bytes allocated to some
value -- which is not possible when you're near the boundary of what
is available for a signed integer.

The result is that a request to allocate a large number is translated
into a small request rather than returning NULL.

Looking at the newest version of Doug Lea's malloc, it seems like he
is handling this by doing a REQUEST_OUT_OF_RANGE check.  I'm not sure
what the best way to handle this would be, however.  I guess newlib
should do the same thing but that's hard to do with the current
macro that is used to handle these types of things.

Any suggestions on how to deal with this problem?

The macro which returns the rounded number of bytes is below.

cgf

#define request2size(req) \
 (((unsigned long)((req) + (SIZE_SZ + MALLOC_ALIGN_MASK)) < \
  (unsigned long)(MINSIZE + MALLOC_ALIGN_MASK)) ? ((MINSIZE + MALLOC_ALIGN_MASK) & ~(MALLOC_ALIGN_MASK)) : \
   (((unsigned long) (req) + (SIZE_SZ + MALLOC_ALIGN_MASK)) & ~(MALLOC_ALIGN_MASK)))


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