lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <alpine.LFD.2.00.1001221743521.13231@localhost.localdomain>
Date:	Fri, 22 Jan 2010 17:47:36 -0800 (PST)
From:	Linus Torvalds <torvalds@...ux-foundation.org>
To:	Andrew Morton <akpm@...ux-foundation.org>
cc:	André Goddard Rosa <andre.goddard@...il.com>,
	linux-kernel@...r.kernel.org, Joe Perches <joe@...ches.com>,
	Frederic Weisbecker <fweisbec@...il.com>
Subject: Re: [PATCH 1/2] string: simplify stricmp()



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
--
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

Powered by Openwall GNU/*/Linux Powered by OpenVZ