]> git.ozlabs.org Git - ccan/blobdiff - ccan/tally/tally.c
tally: fix FreeBSD compile, memleak in tests.
[ccan] / ccan / tally / tally.c
index b89b0600ac301d0f5d088cb5a31176c841e1c8c3..b1839befe3b4016287ded6203767be305e65b657 100644 (file)
@@ -1,4 +1,3 @@
-#include "config.h"
 #include <ccan/tally/tally.h>
 #include <ccan/build_assert/build_assert.h>
 #include <ccan/likely/likely.h>
@@ -7,6 +6,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <assert.h>
+#include <stdlib.h>
 
 #define SIZET_BITS (sizeof(size_t)*CHAR_BIT)
 
@@ -322,7 +322,7 @@ ssize_t tally_total(const struct tally *tally, ssize_t *overflow)
        }
 
        /* If result is negative, make sure we can represent it. */
-       if (tally->total[1] & (1 << (SIZET_BITS-1))) {
+       if (tally->total[1] & ((size_t)1 << (SIZET_BITS-1))) {
                /* Must have only underflowed once, and must be able to
                 * represent result at ssize_t. */
                if ((~tally->total[1])+1 != 0