]> git.ozlabs.org Git - ccan/commitdiff
tally: Slightly simplify tally_new
authorVolker Lendecke <vl@samba.org>
Wed, 10 Aug 2011 17:44:10 +0000 (19:44 +0200)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 31 Aug 2011 01:09:09 +0000 (10:39 +0930)
(Imported from SAMBA commit 066d36a1a635e1115f62c452c49a9830d484c03b)

ccan/tally/tally.c

index 2af7353380f9af18221971aba90d1f7648ab8b2b..a5eedcb951bfafc819701a740bcad64e68f162ac 100644 (file)
@@ -33,14 +33,16 @@ struct tally *tally_new(unsigned buckets)
                return NULL;
        tally = (struct tally *)malloc(
                sizeof(*tally) + sizeof(tally->counts[0])*(buckets-1));
-       if (tally) {
-               tally->max = ((size_t)1 << (SIZET_BITS - 1));
-               tally->min = ~tally->max;
-               tally->total[0] = tally->total[1] = 0;
-               tally->buckets = buckets;
-               tally->step_bits = 0;
-               memset(tally->counts, 0, sizeof(tally->counts[0])*buckets);
+       if (tally == NULL) {
+               return NULL;
        }
+
+       tally->max = ((size_t)1 << (SIZET_BITS - 1));
+       tally->min = ~tally->max;
+       tally->total[0] = tally->total[1] = 0;
+       tally->buckets = buckets;
+       tally->step_bits = 0;
+       memset(tally->counts, 0, sizeof(tally->counts[0])*buckets);
        return tally;
 }