Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

16
OpenBSD's reallocarray extension
Post Flair (click to view more posts with a particular flair)
Post Body

reallocarray(3) is a malloc(3)/realloc(3) extension from OpenBSD, it is very portable and easy to incorporate into existing codebases.

The intention of reallocarray to replace the following idiom:

if ((p = malloc(num * size)) == NULL)
    err(1, "malloc");

..with the much safer:

if ((p = reallocarray(NULL, num, size)) == NULL)
    err(1, "malloc");

In the first example, num * size may lead to an undetected integer multiplication overflow.

reallocarray(3) performs the same overflow detection that is conventionally done by calloc(3), but without the expensive memory zeroing operation. It returns NULL on overflow, with errno set to ENOMEM, as is permitted by standards.

It is now being used extensively by LibreSSL as within OpenBSD's own userland; and in the kernel, as mallocarray(9).

An ISC licensed reference implementation is available here.

Author
Account Strength
100%
Account Age
13 years
Verified Email
Yes
Verified Flair
No
Total Karma
12,722
Link Karma
3,251
Comment Karma
9,052
Profile updated: 6 days ago
Posts updated: 7 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
10 years ago