This is the mail archive of the
newlib@sources.redhat.com
mailing list for the newlib project.
Re: Problems with malloc(LARGEINT) How to fix?
- From: Christopher Faylor <cgf at redhat dot com>
- To: newlib at sources dot redhat dot com
- Date: Mon, 11 Mar 2002 17:15:12 -0500
- Subject: Re: Problems with malloc(LARGEINT) How to fix?
- References: <20020311220042.GA25726@redhat.com>
On Mon, Mar 11, 2002 at 05:00:42PM -0500, Christopher Faylor wrote:
>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.
Oops. That's a modified version of that macro. I added the 'unsigned long's.
They should just be 'long'.
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)))