commit 3cbe3666b87d1c256eddf2d26f2238bfc000083f
Author:     Mattias Andrée <[email protected]>
AuthorDate: Tue Mar 1 19:33:46 2016 +0100
Commit:     Mattias Andrée <[email protected]>
CommitDate: Tue Mar 1 19:33:46 2016 +0100

    zsetu: change macro from CHARS_PER_TYPE to SIZE_MULTIPLE
    
    Signed-off-by: Mattias Andrée <[email protected]>

diff --git a/src/zsetu.c b/src/zsetu.c
index 78b78bb..385403c 100644
--- a/src/zsetu.c
+++ b/src/zsetu.c
@@ -1,7 +1,7 @@
 /* See LICENSE file for copyright and license details. */
 #include "internals"
 
-#define CHARS_PER_TYPE(t)  (sizeof(t) / (BITS_PER_CHAR >> 3))
+#define SIZE_MULTIPLE(fit, in)  ((sizeof(fit) + sizeof(in) - 1) / sizeof(in))
 
 
 void
@@ -11,9 +11,9 @@ zsetu(z_t a, unsigned long long int b)
                SET_SIGNUM(a, 0);
                return;
        }
-       if (a->alloced < CHARS_PER_TYPE(b)) {
-               a->alloced = CHARS_PER_TYPE(b);
-               a->chars = realloc(a->chars, CHARS_PER_TYPE(b) * 
sizeof(*(a->chars)))
+       if (a->alloced < SIZE_MULTIPLE(b, *(a->chars))) {
+               a->alloced = SIZE_MULTIPLE(b, *(a->chars));
+               a->chars = realloc(a->chars, SIZE_MULTIPLE(b, *(a->chars)) * 
sizeof(*(a->chars)))
        }
        SET_SIGNUM(a, 1);
        a->used = 0;

Reply via email to