From: Michael Holzheu <holzheu@linux.vnet.ibm.com>
To: andre.goddard@gmail.com
Cc: akpm@linux-foundation.org, schwidefsky@de.ibm.com,
heiko.carstens@de.ibm.com, linux-kernel@vger.kernel.org
Subject: [PATCH] Fix strim() semantics for strings that have only blanks
Date: Wed, 12 Oct 2011 10:31:57 +0200 [thread overview]
Message-ID: <1318408317.2891.3.camel@br98xy6r> (raw)
Hello Andre,
With git commit 84c95c9acf088c99d8793d78036b67faa5d0b851 a patch from
you went upstream where you wanted to improve 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.
>From 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
Also strim() explicitly does not have "__must_check", in order to use it
without using the return value.
I attached a patch that restores the old strim() semantics.
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
---
lib/string.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
--- a/lib/string.c
+++ b/lib/string.c
@@ -360,7 +360,6 @@ char *strim(char *s)
size_t size;
char *end;
- s = skip_spaces(s);
size = strlen(s);
if (!size)
return s;
@@ -370,7 +369,7 @@ char *strim(char *s)
end--;
*(end + 1) = '\0';
- return s;
+ return skip_spaces(s);
}
EXPORT_SYMBOL(strim);
next reply other threads:[~2011-10-12 8:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-12 8:31 Michael Holzheu [this message]
2011-10-13 23:54 ` [PATCH] Fix strim() semantics for strings that have only blanks Andrew Morton
2011-10-14 8:44 ` Michael Holzheu
2011-10-17 11:24 ` André Goddard Rosa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1318408317.2891.3.camel@br98xy6r \
--to=holzheu@linux.vnet.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=andre.goddard@gmail.com \
--cc=heiko.carstens@de.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=schwidefsky@de.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox