[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20100122162740.11410ac4.akpm@linux-foundation.org>
Date: Fri, 22 Jan 2010 16:27:40 -0800
From: Andrew Morton <akpm@...ux-foundation.org>
To: André Goddard Rosa <andre.goddard@...il.com>
Cc: linux-kernel@...r.kernel.org, torvalds@...ux-foundation.org,
Joe Perches <joe@...ches.com>,
Frederic Weisbecker <fweisbec@...il.com>
Subject: Re: [PATCH 1/2] string: simplify stricmp()
On Sat, 16 Jan 2010 18:57:00 -0200
Andr__ Goddard Rosa <andre.goddard@...il.com> wrote:
> Removes 32 bytes on core2 with gcc 4.4.1:
> text data bss dec hex filename
> 3196 0 0 3196 c7c lib/string-BEFORE.o
> 3164 0 0 3164 c5c lib/string-AFTER.o
>
> Signed-off-by: Andr__ Goddard Rosa <andre.goddard@...il.com>
> cc: Joe Perches <joe@...ches.com>
> cc: Frederic Weisbecker <fweisbec@...il.com>
> cc: Andrew Morton <akpm@...ux-foundation.org>
> ---
> lib/string.c | 34 +++++++++++++++-------------------
> 1 files changed, 15 insertions(+), 19 deletions(-)
>
> diff --git a/lib/string.c b/lib/string.c
> index a1cdcfc..0f86245 100644
> --- a/lib/string.c
> +++ b/lib/string.c
> @@ -36,25 +36,21 @@ int strnicmp(const char *s1, const char *s2, size_t len)
> /* Yes, Virginia, it had better be unsigned */
> unsigned char c1, c2;
>
> - c1 = c2 = 0;
> - if (len) {
> - do {
> - c1 = *s1;
> - c2 = *s2;
> - s1++;
> - s2++;
> - if (!c1)
> - break;
> - if (!c2)
> - break;
> - if (c1 == c2)
> - continue;
> - c1 = tolower(c1);
> - c2 = tolower(c2);
> - if (c1 != c2)
> - break;
> - } while (--len);
> - }
> + if (!len)
> + return 0;
> +
> + do {
> + c1 = *s1++;
> + c2 = *s2++;
> + if (!c1 || !c2)
> + break;
> + if (c1 == c2)
> + continue;
> + c1 = tolower(c1);
> + c2 = tolower(c2);
> + if (c1 != c2)
> + break;
> + } while (--len);
> return (int)c1 - (int)c2;
> }
> EXPORT_SYMBOL(strnicmp);
hm, that function seems a little broken.
If it reaches the end of s1 or s2 it will return (c1 - c2). If however
it detects a difference due to other than end-of-string, it returns
(tolower(c1) - tolower(c2)).
IOW, perhaps it should be performing tolower() in the
I-reached-end-of-string case.
I wonder what strnicmp() is _supposed_ to return..
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists