Skip to content

Commit

Permalink
lib/string.c: fix strim() semantics for strings that have only blanks
Browse files Browse the repository at this point in the history
Commit 84c95c9 ("string: on strstrip(), first remove leading spaces
before running over str") improved� the performance of the strim()
function.

Unfortunately this changed the semantics of strim() and broke my code.
Before the patch it was possible to use strim() without using the return
value for removing trailing spaces from strings that had either only
blanks or only trailing blanks.

Now this does not work any longer for strings that *only* have blanks.

Before patch: "   " -> ""    (empty string)
After patch:  "   " -> "   " (no change)

I think we should remove your patch to restore the old behavior.

The description (lib/string.c):

 * Note that the first trailing whitespace is replaced with a %NUL-terminator

=> The first trailing whitespace of a string that only has whitespace
   characters is the first whitespace

The patch restores the old strim() semantics.

Signed-off-by: Michael Holzheu <[email protected]>
Cc: Andre Goddard Rosa <[email protected]>
Cc: Martin Schwidefsky <[email protected]>
Cc: Heiko Carstens <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Michael Holzheu authored and torvalds committed Nov 1, 2011
1 parent e3816c5 commit 66f6958
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions lib/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ char *strim(char *s)
size_t size;
char *end;

s = skip_spaces(s);
size = strlen(s);
if (!size)
return s;
Expand All @@ -370,7 +369,7 @@ char *strim(char *s)
end--;
*(end + 1) = '\0';

return s;
return skip_spaces(s);
}
EXPORT_SYMBOL(strim);

Expand Down

0 comments on commit 66f6958

Please sign in to comment.