X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftally%2Ftally.c;h=396474b250e0c04be0b8a581a2fddc1bb553c7a4;hp=0d0190795557b60ccfe8d73138dfda2baf99477d;hb=8fc7a90a8db345c4276419d11f8731afc63f65f5;hpb=65c7607d7828bbb212dbbb8d82cd0bb0c5581faf diff --git a/ccan/tally/tally.c b/ccan/tally/tally.c index 0d019079..396474b2 100644 --- a/ccan/tally/tally.c +++ b/ccan/tally/tally.c @@ -1,4 +1,3 @@ -#include "config.h" #include #include #include @@ -7,6 +6,7 @@ #include #include #include +#include #define SIZET_BITS (sizeof(size_t)*CHAR_BIT) @@ -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) {