| Summary: | Add reallocarray wrapper | ||
|---|---|---|---|
| Product: | [Developer tools] valgrind | Reporter: | Paul Floyd <pjfloyd> |
| Component: | general | Assignee: | Julian Seward <jseward> |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | ||
| Priority: | NOR | ||
| Version First Reported In: | 3.22 GIT | ||
| Target Milestone: | --- | ||
| Platform: | Other | ||
| OS: | FreeBSD | ||
| Latest Commit: | Version Fixed/Implemented In: | ||
| Sentry Crash Report: | |||
| Attachments: | initial patch | ||
|
Description
Paul Floyd
2023-10-12 05:15:01 UTC
Also adding a wrapper will slightly improve error messages.
The FreeBSD implementation is
void *
reallocarray(void *optr, size_t nmemb, size_t size)
{
if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
nmemb > 0 && SIZE_MAX / nmemb < size) {
errno = ENOMEM;
return (NULL);
}
return (realloc(optr, size * nmemb));
}
Illumos uses the same source (from OpenBSD)
musl and GNU libc do the same thing but without the square root of MAX_SIZE checks to avoid the division.
Created attachment 162942 [details]
initial patch
Linux expected not yet generated
commit 993cdf80a15ecf2cdaaa10a120cb29949f22605f (HEAD -> master, origin/master, origin/HEAD, bug475498) Author: Paul Floyd <pjfloyd@wanadoo.fr> Date: Thu Nov 9 07:58:02 2023 +0100 Bug 475498 - Add reallocarray wrapper |