summaryrefslogtreecommitdiff
path: root/usr.bin/diff/xmalloc.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2015-04-29 04:00:26 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2015-04-29 04:00:26 +0000
commit0d4a918906e39bd2505fb246023ef1ebe9dfca66 (patch)
treec4ab8bf53a68c2d563202ab4631cb2dd97798473 /usr.bin/diff/xmalloc.c
parent016754927089e58998a9188ada697658caeb65a9 (diff)
Change internal xrealloc() to a idiom-following xreallocarray().
This loses a "new size is 0" failure case. Probably not relevant; and since we develop this in OpenBSD, we'll catch that before someone else imports this... ok millert
Diffstat (limited to 'usr.bin/diff/xmalloc.c')
-rw-r--r--usr.bin/diff/xmalloc.c14
1 files changed, 3 insertions, 11 deletions
diff --git a/usr.bin/diff/xmalloc.c b/usr.bin/diff/xmalloc.c
index 767500c0b07..2eccb0fd63a 100644
--- a/usr.bin/diff/xmalloc.c
+++ b/usr.bin/diff/xmalloc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: xmalloc.c,v 1.5 2015/02/05 12:59:57 millert Exp $ */
+/* $OpenBSD: xmalloc.c,v 1.6 2015/04/29 04:00:25 deraadt Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -52,19 +52,11 @@ xcalloc(size_t nmemb, size_t size)
}
void *
-xrealloc(void *ptr, size_t nmemb, size_t size)
+xreallocarray(void *ptr, size_t nmemb, size_t size)
{
void *new_ptr;
- size_t new_size = nmemb * size;
- if (new_size == 0)
- errx(2, "xrealloc: zero size");
- if (SIZE_MAX / nmemb < size)
- errx(2, "xrealloc: nmemb * size > SIZE_MAX");
- if (ptr == NULL)
- new_ptr = malloc(new_size);
- else
- new_ptr = realloc(ptr, new_size);
+ new_ptr = reallocarray(ptr, nmemb, size);
if (new_ptr == NULL)
err(2, NULL);
return new_ptr;