commit e560794bea8451132e469793ec611c444d49205d
Author: Mattias Andrée <maandree_AT_kth.se>
AuthorDate: Wed Mar 2 21:23:46 2016 +0100
Commit: Mattias Andrée <maandree_AT_kth.se>
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 <maandree_AT_kth.se>
diff --git a/src/ztrunc.c b/src/ztrunc.c
index d4c31de..3d05c6e 100644
--- a/src/ztrunc.c
+++ b/src/ztrunc.c
_AT_@ -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)));
Received on Wed Mar 02 2016 - 21:37:25 CET
This archive was generated by hypermail 2.3.0
: Wed Mar 02 2016 - 21:48:38 CET