X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftally%2Ftally.c;h=0d49319608d2ff6dc53edf9d62429e055c50f152;hb=05b39faed2c73b317f6a7f6f59ec0e8c69e5d5bf;hp=0d0190795557b60ccfe8d73138dfda2baf99477d;hpb=65c7607d7828bbb212dbbb8d82cd0bb0c5581faf;p=ccan diff --git a/ccan/tally/tally.c b/ccan/tally/tally.c index 0d019079..0d493196 100644 --- a/ccan/tally/tally.c +++ b/ccan/tally/tally.c @@ -1,4 +1,4 @@ -#include "config.h" +/* Licensed under LGPLv3+ - see LICENSE file for details */ #include #include #include @@ -7,6 +7,7 @@ #include #include #include +#include #define SIZET_BITS (sizeof(size_t)*CHAR_BIT) @@ -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) {