[U-Boot] [PATCH] Prevent malloc with size 0
Graeme Russ
graeme.russ at gmail.com
Mon Apr 2 06:27:03 CEST 2012
Hi Marek,
On Mon, Apr 2, 2012 at 2:23 PM, Marek Vasut <marek.vasut at gmail.com> wrote:
> Dear Graeme Russ,
>
>> Hi Marek,
>>
>> On Mon, Apr 2, 2012 at 1:36 PM, Marek Vasut <marek.vasut at gmail.com> wrote:
>> > Dear Mike Frysinger,
>> >
>> >> On Sunday 01 April 2012 20:25:44 Graeme Russ wrote:
>> >> > b) The code calling malloc(0) is making a perfectly legitimate
>> >> > assumption
>> >> >
>> >> > based on how glibc handles malloc(0)
>> >>
>> >> not really. POSIX says malloc(0) is implementation defined (so it may
>> >> return a unique address, or it may return NULL). no userspace code
>> >> assuming malloc(0) will return non-NULL is correct.
>> >
>> > Which is your implementation-defined ;-) But I have to agree with this
>> > one. So my vote is for returning NULL.
>>
>> Also, no userspace code assuming malloc(0) will return NULL is correct
>>
>> Point being, no matter which implementation is chosen, it is up to the
>> caller to not assume that the choice that was made was, in fact, the
>> choice that was made.
>>
>> I.e. the behaviour of malloc(0) should be able to be changed on a whim
>> with no side-effects
>>
>> So I think I should change my vote to returning NULL for one reason and
>> one reason only - It is faster during run-time
>
> Well, this still might break some code which assumes otherwise ... like you
> said. And like I said, let's break it because it worked only be a sheer
> coincidence ;-)
+1 your debug() and return NULL solution
Regards,
Graeme
More information about the U-Boot
mailing list