From: Martin Mares Date: Thu, 30 Dec 2010 13:46:09 +0000 (+0100) Subject: Fixed parsing of /proc/loadavg X-Git-Tag: v1.13~3 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=95d38735feda771996883e39a723e9848ca1117b;p=ywho.git Fixed parsing of /proc/loadavg It no longer accesses one byte before the line buffer. --- diff --git a/ywho.c b/ywho.c index 12a2079..15d1b46 100644 --- a/ywho.c +++ b/ywho.c @@ -274,11 +274,14 @@ line2(void) { int i = 3; fgets(line, 256, f); - *strchr(line, '\n') = 0; - z = line-1; + z = strchr(line, '\n'); + if (z) + *z = 0; + z = line; while (i-- && z) { - *z = '/'; + if (z > line) + *z = '/'; z = strchr(z, ' '); } if (z)