aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-03-02 21:23:46 +0100
committerMattias Andrée <maandree@kth.se>2016-03-02 21:23:53 +0100
commite560794bea8451132e469793ec611c444d49205d (patch)
treea27bc7dc035606b13e916084fc5aeff692cc3d47 /src
parentzgcd: optimisation of the first loop (diff)
downloadlibzahl-e560794bea8451132e469793ec611c444d49205d.tar.gz
libzahl-e560794bea8451132e469793ec611c444d49205d.tar.bz2
libzahl-e560794bea8451132e469793ec611c444d49205d.tar.xz
ztrunc: fix bug: bits > .used may lead to incorrect truncation
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--src/ztrunc.c2
1 files changed, 2 insertions, 0 deletions
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)));