From d6987458f21cf1890045f2606d0f8ec4d2225b44 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 3 Mar 2016 23:02:59 +0100 Subject: Cleanup and fix bug in ztrunc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/zload.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'src/zload.c') diff --git a/src/zload.c b/src/zload.c index e03d911..0f5d35b 100644 --- a/src/zload.c +++ b/src/zload.c @@ -1,9 +1,6 @@ /* See LICENSE file for copyright and license details. */ #include "internals" -#include -#include - size_t zload(z_t a, const void *buffer) @@ -12,13 +9,11 @@ zload(z_t a, const void *buffer) a->sign = *((int *)buf), buf += sizeof(int); a->used = *((size_t *)buf), buf += sizeof(size_t); a->alloced = *((size_t *)buf), buf += sizeof(size_t); - if (a->alloced) { - a->chars = realloc(a->chars, a->alloced * sizeof(*(a->chars))); - } else { + if (a->alloced) + zahl_realloc(a, a->alloced); + else a->chars = 0; - } - if (!zzero(a)) { - memcpy(a->chars, buf, a->used * sizeof(*(a->chars))); - } + if (!zzero(a)) + zmemcpy(a->chars, buf, a->used); return sizeof(z_t) - sizeof(a->chars) + (zzero(a) ? 0 : a->used * sizeof(*(a->chars))); } -- cgit v1.2.3-70-g09d2