From: Florian Forster Date: Tue, 26 Jan 2010 23:07:50 +0000 (+0100) Subject: contextswitch plugin: Handle large counter/derive values correctly. X-Git-Tag: collectd-4.9.2~11 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=5cf068c08da44590fb42f5c42507ce5be8a02c45;p=collectd.git contextswitch plugin: Handle large counter/derive values correctly. Using "strtoul" for derive_t values fails for large counter values. Thanks to Martin Merkel for reporting this :) --- diff --git a/src/contextswitch.c b/src/contextswitch.c index 7787203d..06055ca5 100644 --- a/src/contextswitch.c +++ b/src/contextswitch.c @@ -27,7 +27,7 @@ # error "No applicable input method." #endif -static void cs_submit (unsigned long context_switches) +static void cs_submit (derive_t context_switches) { value_t values[1]; value_list_t vl = VALUE_LIST_INIT; @@ -49,7 +49,7 @@ static int cs_read (void) char buffer[64]; int numfields; char *fields[3]; - unsigned long result = 0; + derive_t result = 0; int status = -2; fh = fopen ("/proc/stat", "r"); @@ -72,7 +72,7 @@ static int cs_read (void) errno = 0; endptr = NULL; - result = strtoul(fields[1], &endptr, 10); + result = (derive_t) strtoll (fields[1], &endptr, /* base = */ 10); if ((endptr == fields[1]) || (errno != 0)) { ERROR ("contextswitch plugin: Cannot parse ctxt value: %s", fields[1]);