summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f426ea7)
raw | patch | inline | side by side (parent: f426ea7)
author | Florian Forster <octo@collectd.org> | |
Sun, 11 Mar 2012 11:13:37 +0000 (12:13 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Sun, 11 Mar 2012 11:13:37 +0000 (12:13 +0100) |
Prior to this, the signed variant was used when casting to gauge_t. This caused
problems with values larger than 2^31-1, since they were casted to negative
values.
Hopefully fixes GitHub issue #50.
problems with values larger than 2^31-1, since they were casted to negative
values.
Hopefully fixes GitHub issue #50.
src/snmp.c | patch | blob | history |
diff --git a/src/snmp.c b/src/snmp.c
index 1c2828c1fb2469494e84aafebb6a77d01fadcde9..5c6cce267854f1d41504eea4ef854bade8eb9f9b 100644 (file)
--- a/src/snmp.c
+++ b/src/snmp.c
value_t ret;
uint64_t tmp_unsigned = 0;
int64_t tmp_signed = 0;
- int defined = 1;
+ _Bool defined = 1;
+ /* Set to true when the original SNMP type appears to have been signed. */
+ _Bool prefer_signed = 0;
if ((vl->type == ASN_INTEGER)
|| (vl->type == ASN_UINTEGER)
{
tmp_unsigned = (uint32_t) *vl->val.integer;
tmp_signed = (int32_t) *vl->val.integer;
- DEBUG ("snmp plugin: Parsed int32 value is %"PRIi64".", tmp_signed);
+
+ if ((vl->type == ASN_INTEGER)
+ || (vl->type == ASN_GAUGE))
+ prefer_signed = 1;
+
+ DEBUG ("snmp plugin: Parsed int32 value is %"PRIu64".", tmp_unsigned);
}
else if (vl->type == ASN_COUNTER64)
{
}
else if (type == DS_TYPE_GAUGE)
{
- ret.gauge = NAN;
- if (defined != 0)
+ if (!defined)
+ ret.gauge = NAN;
+ else if (prefer_signed)
ret.gauge = (scale * tmp_signed) + shift;
+ else
+ ret.gauge = (scale * tmp_unsigned) + shift;
}
else if (type == DS_TYPE_DERIVE)
- ret.derive = (derive_t) tmp_signed;
+ {
+ if (prefer_signed)
+ ret.derive = (derive_t) tmp_signed;
+ else
+ ret.derive = (derive_t) tmp_unsigned;
+ }
else if (type == DS_TYPE_ABSOLUTE)
+ {
ret.absolute = (absolute_t) tmp_unsigned;
+ }
else
{
ERROR ("snmp plugin: csnmp_value_list_to_value: Unknown data source "