From 95d38735feda771996883e39a723e9848ca1117b Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Thu, 30 Dec 2010 14:46:09 +0100 Subject: [PATCH] Fixed parsing of /proc/loadavg It no longer accesses one byte before the line buffer. --- ywho.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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) -- 2.39.2