From db20fa00ca9880e6e661befee92e19194fa5e69a Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 5 Feb 2015 12:14:32 +0100 Subject: xmalloc: Make xrealloc() arguments conform to realloc() xrealloc() has an additional nmemb argument compared to realloc() for which it should serve as a wrapper. Since we always call with nmemb = 1, we might as well remove this argument and thus have xrealloc() conform to the realloc() function prototype. Signed-off-by: Tobias Klauser --- xmalloc.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'xmalloc.c') diff --git a/xmalloc.c b/xmalloc.c index 18972fb..75319ff 100644 --- a/xmalloc.c +++ b/xmalloc.c @@ -1,6 +1,7 @@ /* * netsniff-ng - the packet sniffing beast * Copyright 2009, 2010, 2011, 2012 Daniel Borkmann. + * Copyright 2014, 2015 Tobias Klauser * Subject to the GPL, version 2. */ @@ -98,20 +99,16 @@ void *xmemdupz(const void *data, size_t len) return memcpy(xmallocz(len), data, len); } -void *xrealloc(void *ptr, size_t nmemb, size_t size) +void *xrealloc(void *ptr, size_t size) { void *new_ptr; - size_t new_size = nmemb * size; - if (unlikely(new_size == 0)) + if (unlikely(size == 0)) panic("xrealloc: zero size\n"); - if (unlikely(((size_t) ~0) / nmemb < size)) - panic("xrealloc: nmemb * size > SIZE_T_MAX\n"); - new_ptr = realloc(ptr, new_size); + new_ptr = realloc(ptr, size); if (unlikely(new_ptr == NULL)) - panic("xrealloc: out of memory (new_size %zu bytes)\n", - new_size); + panic("xrealloc: out of memory (allocating %zu bytes)\n", size); return new_ptr; } -- cgit v1.2.3-54-g00ecf