Add standalone reallocarray.c from OpenBSD instead of rolling our own.

This commit is contained in:
Todd C. Miller
2015-05-27 10:04:32 -06:00
parent 2bf454b74d
commit 40d72f26e4
4 changed files with 63 additions and 15 deletions

View File

@@ -48,7 +48,6 @@
#elif defined(HAVE_INTTYPES_H)
# include <inttypes.h>
#endif
#include <errno.h>
#include <limits.h>
#define DEFAULT_TEXT_DOMAIN "sudo"
@@ -258,17 +257,3 @@ sudo_evasprintf_v1(char **ret, const char *fmt, va_list args)
sudo_fatal_nodebug(NULL);
return len;
}
#ifndef HAVE_REALLOCARRAY
void *
sudo_reallocarray(void *ptr, size_t nmemb, size_t size)
{
if (nmemb > SIZE_MAX / size) {
errno = EOVERFLOW;
return NULL;
}
size *= nmemb;
return ptr ? realloc(ptr, size) : malloc(size);
}
#endif /* HAVE_REALLOCARRAY */