[PATCH] strstrip remove last blank fix
authorMichael Holzheu <holzheu@de.ibm.com>
Sat, 28 Oct 2006 17:38:47 +0000 (10:38 -0700)
committerLinus Torvalds <torvalds@g5.osdl.org>
Sat, 28 Oct 2006 18:30:54 +0000 (11:30 -0700)
strstrip() does not remove the last blank from strings which only consist
of blanks.

Example:
char string[] = "  ";
strstrip(string);

results in " ", but should produce an empty string!

The following patch solves this problem:

Acked-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Michael Holzheu <holzheu@de.ibm.com>
Acked-by: Pekka Enberg <penberg@cs.helsinki.fi>
Acked-by Joern Engel <joern@wh.fh-wedel.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
lib/string.c

index 6307726..a485d75 100644 (file)
@@ -320,7 +320,7 @@ char *strstrip(char *s)
                return s;
 
        end = s + size - 1;
-       while (end != s && isspace(*end))
+       while (end >= s && isspace(*end))
                end--;
        *(end + 1) = '\0';