diff options
author | 2015-04-29 04:00:25 +0000 | |
---|---|---|
committer | 2015-04-29 04:00:25 +0000 | |
commit | 371275cabfe7ee71db4f4e23b9a5d966b335d3bc (patch) | |
tree | 09cf87945bdcad26b880cf103ee5c9a520f7f53a /usr.bin/diff/xmalloc.c | |
parent | Allow ListenAddress, Port and AddressFamily in any order. bz#68, (diff) | |
download | wireguard-openbsd-371275cabfe7ee71db4f4e23b9a5d966b335d3bc.tar.xz wireguard-openbsd-371275cabfe7ee71db4f4e23b9a5d966b335d3bc.zip |
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.c | 14 |
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; |