]> git.ozlabs.org Git - ccan/commitdiff
tally: don't use SIZE_MAX.
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 6 Jul 2011 05:11:17 +0000 (14:41 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 6 Jul 2011 05:11:17 +0000 (14:41 +0930)
Turns out it's not standard (thanks Samba build farm!)
And the previous test had a hole in it anyway.  This one is more conservative.

ccan/tally/tally.c

index b1839befe3b4016287ded6203767be305e65b657..396474b250e0c04be0b8a581a2fddc1bb553c7a4 100644 (file)
@@ -27,8 +27,8 @@ struct tally *tally_new(unsigned buckets)
        if (buckets == 0)
                buckets = 1;
 
-       /* Check for overflow. */
-       if (buckets && SIZE_MAX / buckets < sizeof(tally->counts[0]))
+       /* Overly cautious check for overflow. */
+       if (sizeof(*tally) * buckets / sizeof(*tally) != buckets)
                return NULL;
        tally = malloc(sizeof(*tally) + sizeof(tally->counts[0])*(buckets-1));
        if (tally) {