summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d556594)
raw | patch | inline | side by side (parent: d556594)
author | Corey Kosak <kosak@google.com> | |
Fri, 22 Jan 2016 21:56:37 +0000 (16:56 -0500) | ||
committer | Marc Fournier <marc.fournier@camptocamp.com> | |
Tue, 26 Jan 2016 06:15:54 +0000 (07:15 +0100) |
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.
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 | patch | blob | history |
diff --git a/src/daemon/plugin.c b/src/daemon/plugin.c
index e7d4e8df2c801b7e6d0a0e6a8bdd4e120cedbf20..29716185db38b7ac59d9dc8a9bfe144812794c04 100644 (file)
--- a/src/daemon/plugin.c
+++ b/src/daemon/plugin.c
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);