From f1552fdc8b98860f22e69d162db295bfb9b49180 Mon Sep 17 00:00:00 2001 From: Corey Kosak Date: Fri, 22 Jan 2016 16:56:37 -0500 Subject: [PATCH] Don't divide by 0 when doing percentages (e.g. with the swap plugin). Prior to this change, if all the values being sent sum to zero, then the calculated percentage is a division by 0 which is either Inf or NaN depending on the numerator. This is not a theoretical concern: it can easily happen if all the input gauges are 0. This change forces the output to be zero if the denominator is zero. --- src/daemon/plugin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/daemon/plugin.c b/src/daemon/plugin.c index e7d4e8df..29716185 100644 --- a/src/daemon/plugin.c +++ b/src/daemon/plugin.c @@ -2272,7 +2272,7 @@ int plugin_dispatch_multivalue (value_list_t const *template, /* {{{ */ case DS_TYPE_GAUGE: vl->values[0].gauge = va_arg (ap, gauge_t); if (store_percentage) - vl->values[0].gauge *= 100.0 / sum; + vl->values[0].gauge *= sum ? (100.0 / sum) : 0; break; case DS_TYPE_ABSOLUTE: vl->values[0].absolute = va_arg (ap, absolute_t); -- 2.11.0