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] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 08 Feb 2019 01:31:49 -0800
From:   Joe Perches <joe@...ches.com>
To:     Alexey Dobriyan <adobriyan@...il.com>, akpm@...ux-foundation.org
Cc:     linux-kernel@...r.kernel.org
Subject: Re: [PATCH] lib/string.c: make strncmp() smaller

On Fri, 2019-02-08 at 10:34 +0300, Alexey Dobriyan wrote:
> Space savings on x86_64:
> 
> 	add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-29 (-29)
> 	Function                                     old     new   delta
> 	strncmp                                       67      38     -29
> 
> Space savings on arm:
> 
> 	add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-60 (-60)
> 	Function                                     old     new   delta
> 	strncmp                                      116      56     -60
[]
> --- a/lib/string.c
> +++ b/lib/string.c
> @@ -344,16 +344,14 @@ EXPORT_SYMBOL(strcmp);
>   */
>  int strncmp(const char *cs, const char *ct, size_t count)
>  {
> -	unsigned char c1, c2;
> +	while (count--) {
> +		unsigned int c1 = *(unsigned char *)cs++;
> +		unsigned int c2 = *(unsigned char *)ct++;
>  
> -	while (count) {
> -		c1 = *cs++;
> -		c2 = *ct++;
>  		if (c1 != c2)
> -			return c1 < c2 ? -1 : 1;
> +			return c1 - c2;

This does change the return value for most comparisons.

Wasn't there a specific reason for -1 and 1?


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ