diff options
Diffstat (limited to 'usr.bin/tmux/xmalloc.c')
-rw-r--r-- | usr.bin/tmux/xmalloc.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/usr.bin/tmux/xmalloc.c b/usr.bin/tmux/xmalloc.c index 6ef8afd47cd..c0e4167fbb9 100644 --- a/usr.bin/tmux/xmalloc.c +++ b/usr.bin/tmux/xmalloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: xmalloc.c,v 1.4 2012/07/10 11:53:01 nicm Exp $ */ +/* $OpenBSD: xmalloc.c,v 1.5 2014/10/08 17:35:58 nicm Exp $ */ /* * Copyright (c) 2004 Nicholas Marriott <nicm@users.sourceforge.net> @@ -68,7 +68,20 @@ xmalloc(size_t size) } void * -xrealloc(void *oldptr, size_t nmemb, size_t size) +xrealloc(void *oldptr, size_t newsize) +{ + void *newptr; + + if (newsize == 0) + fatalx("zero size"); + if ((newptr = realloc(oldptr, newsize)) == NULL) + fatal("xrealloc failed"); + + return (newptr); +} + +void * +xreallocarray(void *oldptr, size_t nmemb, size_t size) { size_t newsize = nmemb * size; void *newptr; @@ -78,7 +91,7 @@ xrealloc(void *oldptr, size_t nmemb, size_t size) if (SIZE_MAX / nmemb < size) fatalx("nmemb * size > SIZE_MAX"); if ((newptr = realloc(oldptr, newsize)) == NULL) - fatal("xrealloc failed"); + fatal("xreallocarray failed"); return (newptr); } |