diff --git a/include/villas/hist.h b/include/villas/hist.h index abb3ea091..9779ffef6 100644 --- a/include/villas/hist.h +++ b/include/villas/hist.h @@ -11,6 +11,7 @@ #define _HIST_H_ #include +#include #include "config.h" @@ -46,7 +47,7 @@ struct hist { }; /** Initialize struct hist with supplied values and allocate memory for buckets. */ -void hist_create(struct hist *h, double start, double end, double resolution); +int hist_create(struct hist *h, double start, double end, double resolution); /** Free the dynamically allocated memory. */ void hist_destroy(struct hist *h); diff --git a/lib/hist.c b/lib/hist.c index 21baa6784..2cda30811 100644 --- a/lib/hist.c +++ b/lib/hist.c @@ -19,7 +19,7 @@ #define VAL(h, i) ((h)->low + (i) * (h)->resolution) #define INDEX(h, v) round((v - (h)->low) / (h)->resolution) -void hist_create(struct hist *h, double low, double high, double resolution) +int hist_create(struct hist *h, double low, double high, double resolution) { h->low = low; h->high = high; @@ -27,7 +27,7 @@ void hist_create(struct hist *h, double low, double high, double resolution) if (resolution > 0) { h->length = (high - low) / resolution; - h->data = alloc(h->length * sizeof(unsigned)); + h->data = alloc(h->length * sizeof(hist_cnt_t)); } else { h->length = 0; @@ -35,6 +35,8 @@ void hist_create(struct hist *h, double low, double high, double resolution) } hist_reset(h); + + return 0; } void hist_destroy(struct hist *h) diff --git a/tests/hist.c b/tests/hist.c index df9c655e8..aeca35701 100644 --- a/tests/hist.c +++ b/tests/hist.c @@ -18,8 +18,10 @@ const int hist_result[] = {}; Test(hist, simple) { struct hist h; + int ret; - hist_create(&h, -100, 100, 1); + ret = hist_create(&h, -100, 100, 1); + cr_assert_eq(ret, 0); for (int i = 0; i < ARRAY_LEN(test_data); i++) hist_put(&h, test_data[i]);