]> git.ozlabs.org Git - ccan/blobdiff - ccan/tally/tally.c
tally: Adapt tally_new to Samba coding conventions
[ccan] / ccan / tally / tally.c
index 2af7353380f9af18221971aba90d1f7648ab8b2b..d67112c2cf6da49017904be9ec91b49f1f11ced5 100644 (file)
@@ -25,22 +25,27 @@ struct tally *tally_new(unsigned buckets)
        struct tally *tally;
 
        /* There is always 1 bucket. */
-       if (buckets == 0)
+       if (buckets == 0) {
                buckets = 1;
+       }
 
        /* Overly cautious check for overflow. */
-       if (sizeof(*tally) * buckets / sizeof(*tally) != buckets)
+       if (sizeof(*tally) * buckets / sizeof(*tally) != 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;
 }