News for hackers. Stuff that matters.
Re:Once upon a time, memory allocators made sense by klodolph on Monday January 18, 2016 @01:27PM (#10925939)
You can make my_realloc() simpler:

    void *my_realloc(void *ptr, size_t size)
    {
        return size ? realloc(ptr, size) : (free(ptr), 0);
    }
According to the C standard, realloc(NULL, size) is guaranteed to be equivalent to malloc(size). From n1548 7.22.3.5 para 3:

> If ptr is a null pointer, the realloc function behaves like the malloc function for the specified size.

Also, free(0) is well-defined. From n1548 7.22.3.3 para 2:

> If ptr is a null pointer, no action occurs.

There are no comments on this comment yet.