]> git.karo-electronics.de Git - karo-tx-linux.git/commit
lib/string.c: fix strim() semantics for strings that have only blanks
authorMichael Holzheu <holzheu@linux.vnet.ibm.com>
Mon, 24 Oct 2011 14:58:58 +0000 (01:58 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Tue, 25 Oct 2011 09:08:08 +0000 (20:08 +1100)
commita990bff580fe4c35ede8e6b698f80d2d4cb2eb0e
tree24adbcdd71206c25bef255ec72bc1e4a9914973c
parent11dbc05588d519f64cb6e75487bf2ecdd77df445
lib/string.c: fix strim() semantics for strings that have only blanks

Commit 84c95c9acf0 ("string: on strstrip(), first remove leading spaces
before running over str") improved\7f 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 <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: Andrew Morton <akpm@linux-foundation.org>
lib/string.c