]> git.ozlabs.org Git - ccan/blobdiff - ccan/tally/tally.c
htable: fix tools/speed.
[ccan] / ccan / tally / tally.c
index b1839befe3b4016287ded6203767be305e65b657..0d49319608d2ff6dc53edf9d62429e055c50f152 100644 (file)
@@ -1,3 +1,4 @@
+/* Licensed under LGPLv3+ - see LICENSE file for details */
 #include <ccan/tally/tally.h>
 #include <ccan/build_assert/build_assert.h>
 #include <ccan/likely/likely.h>
@@ -27,8 +28,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) {