memcpy overlap: quickly detect, diagnose, work around

John Reiser jreiser at bitwagon.com
Tue Nov 30 16:50:16 UTC 2010


On 11/29/2010 05:29 PM, Matt McCutchen wrote:
> Still, you could split the patch into one that just adds
> commented curly braces to existing code and a second with the
> substantive changes, which would be easier for anyone interested to
> review.

Good idea.  I revised the web page.  Here is the patch to that one file:

diff --git a/sysdeps/x86_64/strcmp.S b/sysdeps/x86_64/strcmp.S
index f4fa16c..b228811 100644
--- a/sysdeps/x86_64/strcmp.S
+++ b/sysdeps/x86_64/strcmp.S
@@ -28,8 +28,6 @@
  #undef UPDATE_STRNCMP_COUNTER
-/* Only change: add commented braces for parenthesis matching in editors. */
-
 #ifndef LABEL  /*{*/
 #define LABEL(l) L(l)
 #endif  /*}*/
@@ -139,9 +137,13 @@ L(oop):	movb	(%rdi), %al
 	jne	L(neq)
 	incq	%rdi
 	incq	%rsi
+#ifdef USE_AS_STRNCMP  /*{*/
+	decq	%rdx
+	jz	L(eq)
+#endif  /*}*/
 	testb	%al, %al
 	jnz	L(oop)
-
+L(eq):
 	xorl	%eax, %eax
 	ret
 @@ -150,7 +152,7 @@ L(neq):	movl	$1, %eax
 	cmovbl	%ecx, %eax
 	ret
 END (BP_SYM (STRCMP))
-#else	/* NOT_IN_libc */  /*}{*/
+#else  /*}{ ! NOT_IN_libc */
 # ifdef USE_AS_STRCASECMP_L  /*{*/
 	/* We have to fall back on the C implementation for locales
 	   with encodings not matching ASCII for single bytes.  */

-- 


More information about the devel mailing list