Hacker News new | past | comments | ask | show | jobs | submit login

Neither copy on write nor size checking are specced as part of the calloc() definition.

Here's the specification of calloc from the ISO standard: The calloc function


    #include <stdlib.h>
    void *calloc(size_t nmemb, size_t size);

  The calloc function allocates space for an array of nmemb objects, each of whose size is size. The space is initialized to all bits zero.

  The calloc function returns either a null pointer or a pointer to the allocated space.

An implementation that lets the size overflow and returns a pointer to a block that isn't large enough for "an array of nmemb objects, each of whose size is size" is not conforming with that specification.

That specification gives the implementation exactly two options: return NULL, or return a pointer to a block of sufficient size.

Yes, and that is exactly my point.

The article says you should use calloc because it provides these optimizations. I am saying no, that's goofy, because it is not specced to provide these optimizations.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact