[quagga-dev 8299] Re: zalloc rules

Greg Troxel gdt at ir.bbn.com
Sat Sep 18 15:44:32 BST 2010


paul at jakma.org writes:

> On Fri, 17 Sep 2010, Chris Hall wrote:
>
>> I don't see why a "z" pointer may not be NULL.  I see nothing terribly
>> wicked about a NULL being interpreted as "a thing which I would have
>> zmalloc'ed/zcalloc'ed if I'd needed it yet".
>
> Indeed. Is there evidence of its use being a bug? Why is the following
> pattern wrong, to use:
>
>   zrealloc (mem);
>
> as shorthand for:
>
>   if (<object has been alloced>)
>     zrealloc (mem);
>   else
>     mem = zalloc (...);
>
> ?
>
> (assuming mem ref is NULLed on dealloc)

The problem (may be | is) that in a lot of situations, there may be
(unexpressed) invariants that pointers contain an allocated object.

If consensus is that NULL being an ok value to pass to realloc, then I
don't want to be pigheaded about this - my concern is that there's
likely underlying sloppy code.

If someone finds where this assert hits and we can evaluate a few actual
cases, that would be very interesting.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 194 bytes
Desc: not available
URL: <http://lists.quagga.net/pipermail/quagga-dev/attachments/20100918/e067994a/attachment-0001.sig>


More information about the Quagga-dev mailing list