From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4936 invoked by alias); 16 Jun 2009 17:13:29 -0000 Received: (qmail 4918 invoked by uid 22791); 16 Jun 2009 17:13:29 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 16 Jun 2009 17:13:22 +0000 Received: from sunsite.mff.cuni.cz (localhost [127.0.0.1]) by sunsite.mff.cuni.cz (8.14.3/8.14.3) with ESMTP id n5GHD1xp023121; Tue, 16 Jun 2009 19:13:02 +0200 Received: (from jakub@localhost) by sunsite.mff.cuni.cz (8.14.3/8.14.3/Submit) id n5GHD1up023118; Tue, 16 Jun 2009 19:13:01 +0200 Date: Tue, 16 Jun 2009 17:13:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] Fix x86-64 memchr Message-ID: <20090616171301.GO3101@sunsite.ms.mff.cuni.cz> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.19 (2009-01-05) Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2009-06/txt/msg00007.txt.bz2 Hi! As the testcase shows, if length passed to memchr is above half of address space length, memchr will return NULL instead of the correct result. 2009-06-16 Jakub Jelinek * sysdeps/x86_64/memchr.S (memchr): Use unsigned instead of signed comparisons. * string/test-memchr.c (do_random_tests): Test very large lengths as well. --- libc/sysdeps/x86_64/memchr.S.jj 2009-05-16 19:23:47.000000000 +0200 +++ libc/sysdeps/x86_64/memchr.S 2009-06-16 19:04:08.000000000 +0200 @@ -41,7 +41,7 @@ ENTRY (memchr) movl $16, %esi jnz 1f cmpq %rsi, %rdx - jle 3f + jbe 3f 2: movdqa (%rdi,%rsi), %xmm0 leaq 16(%rsi), %rsi @@ -50,7 +50,7 @@ ENTRY (memchr) testl %ecx, %ecx jnz 1f cmpq %rsi, %rdx - jg 2b + ja 2b 3: xorl %eax, %eax ret @@ -60,7 +60,7 @@ ENTRY (memchr) addq %rcx, %rax leaq -16(%rsi,%rcx), %rsi cmpq %rsi, %rdx - jle 3b + jbe 3b ret END (memchr) --- libc/string/test-memchr.c.jj 2009-05-16 19:23:37.000000000 +0200 +++ libc/string/test-memchr.c 2009-06-16 18:48:34.000000000 +0200 @@ -1,5 +1,5 @@ /* Test and measure memchr functions. - Copyright (C) 1999, 2002, 2003, 2005 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2003, 2005, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. Written by Jakub Jelinek , 1999. @@ -144,7 +144,12 @@ do_random_tests (void) } if (pos < len) - result = (char *) (p + pos + align); + { + size_t r = random (); + if ((r & 31) == 0) + len = ~(uintptr_t) (p + align) - ((r >> 5) & 31); + result = (char *) (p + pos + align); + } else result = NULL; Jakub