From a27ba6e38006c12c48de88600b8cff9f6aabfed7 Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 8 Oct 2014 17:35:58 +0000 Subject: Add xreallocarray and remove nmemb argument from xrealloc. --- xmalloc.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'xmalloc.c') diff --git a/xmalloc.c b/xmalloc.c index cb734edc..49a0eff9 100644 --- a/xmalloc.c +++ b/xmalloc.c @@ -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); } -- cgit From 900f6fc17e6764377a8e293ce742fb41f1add9bd Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 20 Oct 2014 23:27:14 +0000 Subject: Tidy up some includes. --- xmalloc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'xmalloc.c') diff --git a/xmalloc.c b/xmalloc.c index 49a0eff9..b7331ea0 100644 --- a/xmalloc.c +++ b/xmalloc.c @@ -16,10 +16,8 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include +#include -#include -#include #include #include #include -- cgit From 0a1a88d63caf3a0e8b4440686e73e1f0f690e03c Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 20 Oct 2014 23:57:13 +0000 Subject: Better format for printf format attributes. --- xmalloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'xmalloc.c') diff --git a/xmalloc.c b/xmalloc.c index b7331ea0..b1570a3a 100644 --- a/xmalloc.c +++ b/xmalloc.c @@ -94,7 +94,7 @@ xreallocarray(void *oldptr, size_t nmemb, size_t size) return (newptr); } -int printflike2 +int xasprintf(char **ret, const char *fmt, ...) { va_list ap; @@ -119,7 +119,7 @@ xvasprintf(char **ret, const char *fmt, va_list ap) return (i); } -int printflike3 +int xsnprintf(char *buf, size_t len, const char *fmt, ...) { va_list ap; -- cgit