From 371275cabfe7ee71db4f4e23b9a5d966b335d3bc Mon Sep 17 00:00:00 2001 From: deraadt Date: Wed, 29 Apr 2015 04:00:25 +0000 Subject: 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 --- usr.bin/diff/xmalloc.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'usr.bin/diff/xmalloc.c') 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 * Copyright (c) 1995 Tatu Ylonen , 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; -- cgit v1.2.3-59-g8ed1b