public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: "André Goddard Rosa" <andre.goddard@gmail.com>
Cc: linux-kernel@vger.kernel.org, torvalds@linux-foundation.org,
	Joe Perches <joe@perches.com>,
	Frederic Weisbecker <fweisbec@gmail.com>
Subject: Re: [PATCH 1/2] string: simplify stricmp()
Date: Fri, 22 Jan 2010 16:27:40 -0800	[thread overview]
Message-ID: <20100122162740.11410ac4.akpm@linux-foundation.org> (raw)
In-Reply-To: <16ee7c5e218e89f22a28247e4bd3877355f5ae5c.1263675077.git.andre.goddard@gmail.com>

On Sat, 16 Jan 2010 18:57:00 -0200
Andr__ Goddard Rosa <andre.goddard@gmail.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@gmail.com>
> cc: Joe Perches <joe@perches.com>
> cc: Frederic Weisbecker <fweisbec@gmail.com>
> cc: Andrew Morton <akpm@linux-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..

  reply	other threads:[~2010-01-23  0:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-16 20:56 [PATCH 0/2] Fix recently introduced strnstr() to not search past NUL André Goddard Rosa
2010-01-16 20:57 ` [PATCH 1/2] string: simplify stricmp() André Goddard Rosa
2010-01-23  0:27   ` Andrew Morton [this message]
2010-01-23  1:47     ` Linus Torvalds
2010-01-16 20:57 ` [PATCH 2/2] string: teach strnstr() to not search past NUL-terminator André Goddard Rosa
2010-01-17 23:47   ` Alex Riesen
2010-01-18  1:47   ` Li Zefan
2010-01-18 15:10     ` 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=20100122162740.11410ac4.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=andre.goddard@gmail.com \
    --cc=fweisbec@gmail.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /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