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/zrsh.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'src/zrsh.c') diff --git a/src/zrsh.c b/src/zrsh.c index 649ebb3..ebc00d7 100644 --- a/src/zrsh.c +++ b/src/zrsh.c @@ -1,9 +1,6 @@ /* See LICENSE file for copyright and license details. */ #include "internals" -#include -#include - void zrsh(z_t a, z_t b, size_t bits) @@ -11,8 +8,7 @@ zrsh(z_t a, z_t b, size_t bits) size_t i, chars, cbits; if (!bits) { - if (a != b) - zset(a, b); + SET(a, b); return; } @@ -28,14 +24,12 @@ zrsh(z_t a, z_t b, size_t bits) if (chars && a == b) { a->used -= chars; - memmove(a->chars, a->chars + chars, a->used * sizeof(*(a->chars))); + zmemmove(a->chars, a->chars + chars, a->used); } else if (a != b) { a->used = b->used - chars; - if (a->alloced < a->used) { - a->alloced = a->used; - a->chars = realloc(a->chars, a->used * sizeof(*(a->chars))); - } - memcpy(a->chars, b->chars + chars, a->used * sizeof(*(a->chars))); + if (a->alloced < a->used) + zahl_realloc(a->chars, a->used); + zmemcpy(a->chars, b->chars + chars, a->used); } a->chars[0] >>= bits; -- cgit v1.2.3-70-g09d2