提交 66f6958e 编写于 作者: M Michael Holzheu 提交者: Linus Torvalds

lib/string.c: fix strim() semantics for strings that have only blanks

Commit 84c95c9a ("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: NMichael Holzheu <holzheu@linux.vnet.ibm.com>
Cc: Andre Goddard Rosa <andre.goddard@gmail.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 e3816c54
...@@ -360,7 +360,6 @@ char *strim(char *s) ...@@ -360,7 +360,6 @@ char *strim(char *s)
size_t size; size_t size;
char *end; char *end;
s = skip_spaces(s);
size = strlen(s); size = strlen(s);
if (!size) if (!size)
return s; return s;
...@@ -370,7 +369,7 @@ char *strim(char *s) ...@@ -370,7 +369,7 @@ char *strim(char *s)
end--; end--;
*(end + 1) = '\0'; *(end + 1) = '\0';
return s; return skip_spaces(s);
} }
EXPORT_SYMBOL(strim); EXPORT_SYMBOL(strim);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册