Re:How to C in 2016
by MichaelMoser123 on Saturday January 09, 2016 @03:56AM
(#10870574)
actually openbsd has something like this: mallocarray [1] and reallocarray [2] (OMG realloc) actually here [3] they say that use of these function in libressl and the openbsd port of the http server, etc.
[1] http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man9/...
[2] http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/...
Calloc has another benefit: if you calculate size by n * sizeof(kuku) then it will detect integer overflow (this can be very important for security sensitive stuff that deals with untrusted input), if you did the computation before that and passed calloc( size, 1) then this multiplication and check is another few cycles wasted.
I wonder if they could have done a standard library allocation function like calloc that does the multiplication with overflow detection, does not zero out memory and that returns NULL on zero arguments - but that would be too much to ask.