aboutsummaryrefslogtreecommitdiffstats
path: root/src/zload.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-03-03 23:02:59 +0100
committerMattias Andrée <maandree@kth.se>2016-03-03 23:02:59 +0100
commitd6987458f21cf1890045f2606d0f8ec4d2225b44 (patch)
tree90afabbea01b01c4dedcb41748eb534ce04fbf77 /src/zload.c
parentzsets: minor optimisation (diff)
downloadlibzahl-d6987458f21cf1890045f2606d0f8ec4d2225b44.tar.gz
libzahl-d6987458f21cf1890045f2606d0f8ec4d2225b44.tar.bz2
libzahl-d6987458f21cf1890045f2606d0f8ec4d2225b44.tar.xz
Cleanup and fix bug in ztrunc
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/zload.c')
-rw-r--r--src/zload.c15
1 files changed, 5 insertions, 10 deletions
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 <stdlib.h>
-#include <string.h>
-
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)));
}