[webkit-dev] malloc(0)

Zoltan Horvath zoltan at webkit.org
Wed Jun 13 02:09:37 PDT 2012


The bug report about fastMalloc(0):

Brewmp had conditions for fastMalloc(0) earlier, but it was removed in:


On Wed, 13 Jun 2012 00:08:48 +0200, Adam Barth <abarth at webkit.org> wrote:

> There was some discussion about how to handle malloc(0) a year or so
> ago.  I don't remember if it was on webkit-dev, but you might want to
> check the archives.  Eric Seidel might remember what conclusions (if
> any) we came to.
> Adam
> On Tue, Jun 12, 2012 at 3:03 PM, Myles C. Maxfield
> <myles.maxfield at gmail.com> wrote:
>> Hello,
>> I'm compiling WebKit with a malloc() implementation that returns NULL
>> for malloc(0). According to C99, this is valid: "If the size of the
>> space requested is zero, the behavior is implementation- defined:
>> either a null pointer is returned, or the behavior is as if the size
>> were some nonzero value, except that the returned pointer shall not be
>> used to access an object."
>> I noticed that this caused a problem in one particular place
>> (WTF::StringImpl::getData16SlowCase()) where the code allocates
>> (constant * length) bytes for an (empty) string, and provides an
>> accessor that exposes this pointer. This pointer was being passed to
>> ICU, which didn't perform the requested function because it looked
>> like one of the arguments was invalid, even though it was just empty.
>> I have worked around this one particular occurrence in my local
>> version of WebKit fork, but I'm wondering how often this pattern
>> occurs. Is my fix worth upstreaming?  Is it worth trying to find,
>> "fix," and upstream every occurrence of this pattern? Or is this
>> particular behavior of malloc() an unstated requirement of building
>> WebKit? If the latter is true, perhaps it's worth explicitly stating
>> this somewhere? What is the opinion of the community?
>> Thanks,
>> Myles
>> _______________________________________________
>> webkit-dev mailing list
>> webkit-dev at lists.webkit.org
>> http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev

More information about the webkit-dev mailing list