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-next>] [day] [month] [year] [list]
Message-ID: <20160826200120.GA1852@p183.telecom.by>
Date:   Fri, 26 Aug 2016 23:01:20 +0300
From:   Alexey Dobriyan <adobriyan@...il.com>
To:     akpm@...ux-foundation.org
Cc:     linux-kernel@...r.kernel.org
Subject: [PATCH] smaller strlen()

gcc prefers "*s++" style code for some reason, doesn't unroll loop
condition check once. Kernel strings are small but they aren't of 0
length, so that additional branch was almost never taken.

	$ ./scripts/bloat-o-meter ../vmlinux-000 ../obj/vmlinux
	strlen         30      26      -4
	strlcpy        71      64      -7
	strlcat       120      99     -21

strlcpy() and strlcat() are collateral damage :^)

Signed-off-by: Alexey Dobriyan <adobriyan@...il.com>
---

 lib/string.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

--- a/lib/string.c
+++ b/lib/string.c
@@ -476,11 +476,11 @@ EXPORT_SYMBOL(strim);
  */
 size_t strlen(const char *s)
 {
-	const char *sc;
+	const char *s0 = s;
 
-	for (sc = s; *sc != '\0'; ++sc)
+	while (*s++)
 		/* nothing */;
-	return sc - s;
+	return s - s0 - 1;
 }
 EXPORT_SYMBOL(strlen);
 #endif

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ