From: Rusty Russell Date: Wed, 20 Oct 2010 02:21:50 +0000 (+1030) Subject: tally: fixes for 64 bit machines. X-Git-Url: https://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=65c7607d7828bbb212dbbb8d82cd0bb0c5581faf tally: fixes for 64 bit machines. --- diff --git a/ccan/tally/tally.c b/ccan/tally/tally.c index b89b0600..0d019079 100644 --- a/ccan/tally/tally.c +++ b/ccan/tally/tally.c @@ -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 diff --git a/ccan/tally/test/run-total.c b/ccan/tally/test/run-total.c index 1114a6ee..d7d73e58 100644 --- a/ccan/tally/test/run-total.c +++ b/ccan/tally/test/run-total.c @@ -38,14 +38,17 @@ int main(void) tally_add(tally, max); total = tally_total(tally, &overflow); ok1(overflow == 0); - ok1((size_t)total == 0xFFFFFFFE); + ok1((size_t)total == (size_t)-2); ok1(tally_total(tally, NULL) == max); /* Overflow into upper size_t. */ tally_add(tally, max); total = tally_total(tally, &overflow); ok1(overflow == 1); - ok1((size_t)total == 0x7FFFFFFD); + if (sizeof(size_t) == 4) + ok1((size_t)total == 0x7FFFFFFD); + else if (sizeof(size_t) == 8) + ok1((size_t)total == 0x7FFFFFFFFFFFFFFDULL); ok1(tally_total(tally, NULL) == max); free(tally);