Commit 65c7607d authored by Rusty Russell's avatar Rusty Russell

tally: fixes for 64 bit machines.

parent 57d7208e
......@@ -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
......
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment