commit e560794bea8451132e469793ec611c444d49205d
Author:     Mattias Andrée <[email protected]>
AuthorDate: Wed Mar 2 21:23:46 2016 +0100
Commit:     Mattias Andrée <[email protected]>
CommitDate: Wed Mar 2 21:23:53 2016 +0100

    ztrunc: fix bug: bits > .used may lead to incorrect truncation
    
    Signed-off-by: Mattias Andrée <[email protected]>

diff --git a/src/ztrunc.c b/src/ztrunc.c
index d4c31de..3d05c6e 100644
--- 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)));

Reply via email to