commit e560794bea8451132e469793ec611c444d49205d
parent 2ce357e830db90b9a431362c66bdcf00e05e651e
Author: Mattias Andrée <maandree@kth.se>
Date: Wed, 2 Mar 2016 21:23:46 +0100
ztrunc: fix bug: bits > .used may lead to incorrect truncation
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat:
1 file changed, 2 insertions(+), 0 deletions(-)
diff --git a/src/ztrunc.c b/src/ztrunc.c
@@ -16,6 +16,8 @@ ztrunc(z_t a, z_t b, size_t bits)
chars = CEILING_BITS_TO_CHARS(bits);
a->sign = b->sign;
a->used = chars < b->used ? chars : b->used;
+ if (a->used < chars)
+ bits = 0;
if (a->alloced < b->alloced) {
a->alloced = b->alloced;
a->chars = realloc(a->chars, b->alloced * sizeof(*(a->chars)));