From: Linus Torvalds <torvalds@linux-foundation.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "André Goddard Rosa" <andre.goddard@gmail.com>,
linux-kernel@vger.kernel.org, "Joe Perches" <joe@perches.com>,
"Frederic Weisbecker" <fweisbec@gmail.com>
Subject: Re: [PATCH 1/2] string: simplify stricmp()
Date: Fri, 22 Jan 2010 17:47:36 -0800 (PST) [thread overview]
Message-ID: <alpine.LFD.2.00.1001221743521.13231@localhost.localdomain> (raw)
In-Reply-To: <20100122162740.11410ac4.akpm@linux-foundation.org>
On Fri, 22 Jan 2010, Andrew Morton wrote:
>
> 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.
No, it doesn't matter. It's like strcmp - it returns "positive, negative
or zero" depending on whether the string compared bigger than, smaller
than or equal.
So "(int)c1 - (int)c2" is just a way to do that. And if the string ends
and c1 or c2 is NUL, there's no point in doing the "tolower()", because it
doesn't matter what the other character is: the sign is all that matters
(or, if they are equally long, and both c1 and c2 are zero, then 0).
> I wonder what strnicmp() is _supposed_ to return..
Same as strncmp.
We could make it always return -1/0/+1 (many libraries do that - then the
return value is guaranteed to also fit in a 'char', not just an 'int'),
but it really shouldn't matter for any correct caller.
Linus
next prev parent reply other threads:[~2010-01-23 1:47 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
2010-01-23 1:47 ` Linus Torvalds [this message]
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=alpine.LFD.2.00.1001221743521.13231@localhost.localdomain \
--to=torvalds@linux-foundation.org \
--cc=akpm@linux-foundation.org \
--cc=andre.goddard@gmail.com \
--cc=fweisbec@gmail.com \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.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
all inboxes | Powered by JetHome®