diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2015-02-05 12:14:32 +0100 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2015-02-05 12:14:32 +0100 |
commit | db20fa00ca9880e6e661befee92e19194fa5e69a (patch) | |
tree | 2f1832d48357c53e9285f870478cadaff663b4f4 /xmalloc.c | |
parent | 42e233eab7e6f5eb1a63545c526aa7dd34945bef (diff) |
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 <tklauser@distanz.ch>
Diffstat (limited to 'xmalloc.c')
-rw-r--r-- | xmalloc.c | 13 |
1 files changed, 5 insertions, 8 deletions
@@ -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; } |