[collectd] int overflow: patch for irq plugin

Tomasz Pala gotar at polanet.pl
Sat Apr 18 18:10:27 CEST 2009


On Sat, Apr 18, 2009 at 17:45:00 +0200, Tomasz Pala wrote:

> 214: 2621368360 2621463385 2621343444 2621386931    2349184         28         35         32   PCI-MSI-edge      eth0
> 
> Here LONG_MAX (2147483647L) overflows in 10 days uptime and strtol()
> returns the same value.

Actually I see in kernel sources that this is just unsigned, so it
overflows at ULONG_MAX - this one is more appropriate.

-- 
Tomasz Pala <gotar at pld-linux.org>
-------------- next part --------------
--- irq.c.orig	2009-03-17 14:47:15.000000000 +0100
+++ irq.c	2009-04-18 17:11:44.000000000 +0200
@@ -151,8 +151,8 @@
 	FILE *fh;
 	char buffer[BUFSIZE];
 	unsigned int irq;
-	unsigned int irq_value;
-	long value;
+	unsigned long long irq_value;
+	unsigned value;
 	char *endptr;
 	int i;
 
@@ -182,7 +182,7 @@
 		for (i = 1; i < fields_num; i++)
 		{
 			errno = 0;
-			value = strtol (fields[i], &endptr, 10);
+			value = strtoul (fields[i], &endptr, 10);
 
 			if ((*endptr != '\0') || (errno != 0))
 				break;


More information about the collectd mailing list