]> git.ozlabs.org Git - ccan/blobdiff - ccan/tally/tally.c
tally: Slightly simplify tally_new
[ccan] / ccan / tally / tally.c
index 0d49319608d2ff6dc53edf9d62429e055c50f152..a5eedcb951bfafc819701a740bcad64e68f162ac 100644 (file)
@@ -31,15 +31,18 @@ struct tally *tally_new(unsigned buckets)
        /* 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) {
-               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);
+       tally = (struct tally *)malloc(
+               sizeof(*tally) + sizeof(tally->counts[0])*(buckets-1));
+       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;
 }
 
@@ -449,7 +452,7 @@ char *tally_histogram(const struct tally *tally,
                        largest_bucket = tally->counts[i];
        }
 
-       p = graph = malloc(height * (width + 1) + 1);
+       p = graph = (char *)malloc(height * (width + 1) + 1);
        if (!graph) {
                free(tmp);
                return NULL;