From 203c3841fc6bf9bd2b71ff9ce8e86874375eec1e Mon Sep 17 00:00:00 2001 From: Damien Lespiau Date: Fri, 26 Jun 2015 13:55:01 +0100 Subject: stats: Zero the whole structure at init() time Because the structure started small, I initialized every member directly, but that means that the new fields added weren't properly initialized (sigh!). Zero the whole thing first then. Also, the punishment for introducing a bug should be to write the corresponding unit test. It's not a perfect one, but I'll take it. Signed-off-by: Damien Lespiau --- lib/igt_stats.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/igt_stats.c') diff --git a/lib/igt_stats.c b/lib/igt_stats.c index 65c0ac62..67ee9473 100644 --- a/lib/igt_stats.c +++ b/lib/igt_stats.c @@ -23,16 +23,18 @@ */ #include +#include #include "igt_core.h" #include "igt_stats.h" void igt_stats_init(igt_stats_t *stats, unsigned int capacity) { + memset(stats, 0, sizeof(*stats)); + stats->values = calloc(capacity, sizeof(*stats->values)); igt_assert(stats->values); stats->capacity = capacity; - stats->n_values = 0; } void igt_stats_fini(igt_stats_t *stats) -- cgit v1.2.3