From af7a902d74a7926693f55da9e21a67dde46931d4 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 6 Jul 2011 14:41:17 +0930 Subject: [PATCH] tally: don't use SIZE_MAX. 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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ccan/tally/tally.c b/ccan/tally/tally.c index b1839bef..396474b2 100644 --- a/ccan/tally/tally.c +++ b/ccan/tally/tally.c @@ -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) { -- 2.39.2