This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: i386 optimized string functions incorrectly treat size_t argument as ssize_t
- From: Mike Frysinger <vapier at gentoo dot org>
- To: libc-alpha at sources dot redhat dot com
- Date: Fri, 2 Sep 2005 01:46:11 -0400
- Subject: Re: i386 optimized string functions incorrectly treat size_t argument as ssize_t
- References: <200508312122.18323.vapier@gentoo.org>
On Wednesday 31 August 2005 09:22 pm, Mike Frysinger wrote:
> find attached a patch which should resolve the issue by utilizing 'jz'
> (plus a trick) instead of 'js'
previous patch introduced a one-off error in strncpy on a different border
case ... i missed the usage of 'rep'
find attached a fixed version
-mike
Index: sysdeps/i386/bits/string.h
===================================================================
RCS file: /cvs/glibc/libc/sysdeps/i386/bits/string.h,v
retrieving revision 1.23
diff -u -p -r1.23 string.h
--- sysdeps/i386/bits/string.h 15 Jun 2004 20:11:53 -0000 1.23
+++ sysdeps/i386/bits/string.h 2 Sep 2005 05:41:29 -0000
@@ -385,13 +385,15 @@ strncpy (char *__dest, __const char *__s
register unsigned long int __d0, __d1, __d2;
__asm__ __volatile__
("cld\n"
+ "incl %2\n"
"1:\n\t"
"decl %2\n\t"
- "js 2f\n\t"
+ "jz 2f\n\t"
"lodsb\n\t"
"stosb\n\t"
"testb %%al,%%al\n\t"
"jne 1b\n\t"
+ "decl %2\n"
"rep; stosb\n"
"2:"
: "=&S" (__d0), "=&D" (__d1), "=&c" (__d2)
@@ -436,9 +438,10 @@ strncat (char *__dest, __const char *__s
"repne; scasb\n\t"
"decl %1\n\t"
"movl %4,%2\n"
+ "incl %2\n"
"1:\n\t"
"decl %2\n\t"
- "js 2f\n\t"
+ "jz 2f\n\t"
"lodsb\n\t"
"stosb\n\t"
"testb %%al,%%al\n\t"
@@ -496,9 +499,10 @@ strncmp (__const char *__s1, __const cha
register int __res;
__asm__ __volatile__
("cld\n"
+ "incl %3\n"
"1:\n\t"
"decl %3\n\t"
- "js 2f\n\t"
+ "jz 2f\n\t"
"lodsb\n\t"
"scasb\n\t"
"jne 3f\n\t"