From 16fe8dab7c1fede87f6bdbfbbcbf19f64d60648a Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Mon, 2 Nov 2015 11:30:01 +0100 Subject: stats: Report group indices as unsigned int Currently the unsigned group index value is silently being cast to (signed) int in the log and statsd reporter code. If the resulting value is negative (which can happen for instance with MMCTX counters), the index is assumed to be unset. This commit changes the affected types to unsigned. The index value 0 is then the only value indicating an unset group. Sponsored-by: On-Waves ehf --- src/stats.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/stats.c b/src/stats.c index 155f8a2c..4d5a1f57 100644 --- a/src/stats.c +++ b/src/stats.c @@ -334,11 +334,11 @@ struct osmo_stats_reporter *osmo_stats_reporter_create_log(const char *name) static int osmo_stats_reporter_log_send(struct osmo_stats_reporter *srep, const char *type, - const char *name1, int index1, const char *name2, int value, + const char *name1, unsigned int index1, const char *name2, int value, const char *unit) { LOGP(DSTATS, LOGL_INFO, - "stats t=%s p=%s g=%s i=%d n=%s v=%d u=%s\n", + "stats t=%s p=%s g=%s i=%u n=%s v=%d u=%s\n", type, srep->name_prefix ? srep->name_prefix : "", name1 ? name1 : "", index1, name2, value, unit ? unit : ""); @@ -359,7 +359,7 @@ static int osmo_stats_reporter_log_send_counter(struct osmo_stats_reporter *srep desc->name, value, NULL); else return osmo_stats_reporter_log_send(srep, "c", - NULL, -1, + NULL, 0, desc->name, value, NULL); } @@ -442,7 +442,7 @@ static int osmo_stats_reporter_statsd_close(struct osmo_stats_reporter *srep) } static int osmo_stats_reporter_statsd_send(struct osmo_stats_reporter *srep, - const char *name1, int index1, const char *name2, int value, + const char *name1, unsigned int index1, const char *name2, int value, const char *unit) { char *buf; @@ -452,8 +452,8 @@ static int osmo_stats_reporter_statsd_send(struct osmo_stats_reporter *srep, int old_len = msgb_length(srep->buffer); if (name1) { - if (index1 > 0) - fmt = "%1$s.%2$s.%6$d.%3$s:%4$d|%5$s"; + if (index1 != 0) + fmt = "%1$s.%2$s.%6$u.%3$s:%4$d|%5$s"; else fmt = "%1$s.%2$s.%3$s:%4$d|%5$s"; } else { @@ -517,7 +517,7 @@ static int osmo_stats_reporter_statsd_send_counter(struct osmo_stats_reporter *s desc->name, delta, "c"); else return osmo_stats_reporter_statsd_send(srep, - NULL, -1, + NULL, 0, desc->name, delta, "c"); } @@ -526,7 +526,8 @@ static int osmo_stats_reporter_statsd_send_item(struct osmo_stats_reporter *srep const struct osmo_stat_item_desc *desc, int value) { return osmo_stats_reporter_statsd_send(srep, - statg->desc->group_name_prefix, statg->idx, + statg->desc->group_name_prefix, + statg->idx, desc->name, value, desc->unit); } -- cgit v1.2.3