[Patch] fix unsigned long fast_strtoul_10(char **endptr) for Linux 2.4

walter harms wharms at bfs.de
Mon Feb 27 17:56:31 UTC 2012


Hi list,
Enabling the fast proc scan code for linux2.4 causes top
to display strange numbers [see:possible bug in proc fast scan code]

the reason for this is that the last char in proc/$$/stat is "\n".
This is no problem for > 2.4 since the stats line contains additional chars.

Please be aware that the current code does NOT stop at \0 !  adding more
tokens to read will cause the code to read beyond \0 !

i also killed the variable c what saves 1 byte.

re,
 wh

Signed-off-by: wharms <wharms at bfs.de>

--- procps.c.org        2012-02-20 19:22:58.000000000 +0100
+++ procps.c    2012-02-27 18:45:11.000000000 +0100
@@ -143,12 +143,11 @@
 /* We cut a lot of corners here for speed */
 static unsigned long fast_strtoul_10(char **endptr)
 {
-       char c;
        char *str = *endptr;
        unsigned long n = *str - '0';

-       while ((c = *++str) != ' ')
-               n = n*10 + (c - '0');
+       while ( *str > ' ')
+               n = n*10 + ( *str++ - '0');

        *endptr = str + 1; /* We skip trailing space! */
        return n;


More information about the busybox mailing list