]> mj.ucw.cz Git - ywho.git/commitdiff
Fixed parsing of /proc/loadavg
authorMartin Mares <mj@ucw.cz>
Thu, 30 Dec 2010 13:46:09 +0000 (14:46 +0100)
committerMartin Mares <mj@ucw.cz>
Thu, 30 Dec 2010 13:46:09 +0000 (14:46 +0100)
It no longer accesses one byte before the line buffer.

ywho.c

diff --git a/ywho.c b/ywho.c
index 12a2079cb59990dcaafbbede8850dfd7a1b17183..15d1b46da203a6b38e3ea269b3220f0c45df286c 100644 (file)
--- 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)