> On Apr 15, 2015, at 12:51 PM, Jed Brown <[email protected]> wrote:
> 
> Lisandro Dalcin <[email protected]> writes:
>> 2) https://bitbucket.org/petsc/petsc/branch/dalcinl/petscmalloc-1
>> 
>> This one no longer special-cases zero-sized allocations. It fixes all
>> the PetscMallocK() macros.
>> 
>> If we ever find a system where system malloc(0) returns NULL, 
> 
> Why is this a problem?  I would just accept what malloc(0) returns.

   How to handle MallocK() where say the second item has length zero? Do we 
return a NULL for that item (as current code), the same address as the previous 
object (means if the user writes to that location they have bugs that are 
difficult to detect) or the special value that malloc(0) returns (how to get 
that special value? We can't call malloc(0) each time because there is no place 
to call free() on them with the FreeK().


> 
>> we can use an obvious approach like in Python sources:
>> https://hg.python.org/cpython/file/582e8e71f635/Objects/obmalloc.c#l53
> 
> Yuck.  This can hide real off-by-one errors from Valgrind.

Reply via email to