Skip to contentSkip to conversation

strstrip remove last blank fix

PATCH In review Michael Holzheu 3 participants 3 messages Oct 26, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 strstrip remove last blank fix

Hi Pekka,

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:

---

 lib/string.c |    2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)
lib/string.c +1 -1
diff -Naurp linux-2.6.18/lib/string.c linux-2.6.18-strstrip-fix/lib/string.c
@@ -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';
 
Acked-by on v1 1/1
#1 lore raw
Quoted 2 lines · Michael Holzheu

strstrip() does not remove the last blank from strings which only consist of blanks.

[snip]

Quoted 12 lines

---

 lib/string.c |    2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)

diff -Naurp linux-2.6.18/lib/string.c linux-2.6.18-strstrip-fix/lib/string.c

lib/string.c char *strstrip(char *s) · line 325

Quoted 7 lines
lib/string.c +1 -1
@@ -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';

Looks good, thanks! Andrew, can you please pick up this patch?