From 1c6780be239b72e2abb39eb2e1c29e5589acc37b Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Sun, 17 Feb 2019 22:23:15 +0100 Subject: [PATCH] stats: properly handle invalid metric and type names --- include/villas/stats.h | 2 ++ lib/stats.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/villas/stats.h b/include/villas/stats.h index 3266d21d3..a7a75e9e5 100644 --- a/include/villas/stats.h +++ b/include/villas/stats.h @@ -44,6 +44,7 @@ enum stats_format { }; enum stats_metric { + STATS_METRIC_INVALID = -1, STATS_METRIC_SKIPPED, /**< Counter for skipped samples due to hooks. */ STATS_METRIC_REORDERED, /**< Counter for reordered samples. */ STATS_METRIC_GAP_SAMPLE, /**< Histogram for inter sample timestamps (as sent by remote). */ @@ -53,6 +54,7 @@ enum stats_metric { }; enum stats_type { + STATS_TYPE_INVALID = -1, STATS_TYPE_LAST, STATS_TYPE_HIGHEST, STATS_TYPE_LOWEST, diff --git a/lib/stats.c b/lib/stats.c index e8df3a5b5..b48d429b9 100644 --- a/lib/stats.c +++ b/lib/stats.c @@ -70,7 +70,7 @@ enum stats_metric stats_lookup_metric(const char *str) return d->metric; } - return -1; + return STATS_METRIC_INVALID; } enum stats_type stats_lookup_type(const char *str) @@ -82,7 +82,7 @@ enum stats_type stats_lookup_type(const char *str) return d->type; } - return -1; + return STATS_TYPE_INVALID; } int stats_init(struct stats *s, int buckets, int warmup)