From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/4852 Path: news.gmane.org!not-for-mail From: Timo Teras Newsgroups: gmane.linux.lib.musl.general Subject: Re: memmem() - is it correct? Date: Wed, 9 Apr 2014 15:54:03 +0300 Message-ID: <20140409155403.2d4060a0@vostro> References: <20140409100840.GD21662@example.net> <20140409131903.70876825@vostro> <20140409104925.GE21662@example.net> <20140409155116.30ec723a@vostro> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1397047970 13220 80.91.229.3 (9 Apr 2014 12:52:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 9 Apr 2014 12:52:50 +0000 (UTC) Cc: musl@lists.openwall.com To: u-igbb@aetey.se Original-X-From: musl-return-4856-gllmg-musl=m.gmane.org@lists.openwall.com Wed Apr 09 14:52:43 2014 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1WXrze-0007ig-6p for gllmg-musl@plane.gmane.org; Wed, 09 Apr 2014 14:52:42 +0200 Original-Received: (qmail 5510 invoked by uid 550); 9 Apr 2014 12:52:40 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 5502 invoked from network); 9 Apr 2014 12:52:40 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=BJBQionfeeKDM4fHr84Y5Xyn/2pGqDKRg22I1VCqcgs=; b=eZWvTjp1Masr4qPqsSo/OVlekBvS9RIEvXIJGwWYhYXuud6E9csYPRdvuIs4/EZJrr 7U3rOri9QCfg/mLndxHziVK6xBmFcHSCX4lWRn46fgViTJpjYqIHm2Hb2GjOHJ9YZaud 0AxzP7TgF29ndy9YOXOP9FKRrDiLiPJjAbTPkngq8LIrFs+Ec22PSnh0X7zAsUz6QLza Rwm8HhP+9MuAcrBjjNokMSmP4rrXo1BIVnEUYR8oPxsm+lxj6AK9WQUy/2u7kHg/x7+S Rf+fP6XzFhHZMXE9zZhkMhfMNffWx3jpaXWhNBpYLgQDdi0WazBgc4TVIPeCMZRWrQ0+ d5Bw== X-Received: by 10.152.42.230 with SMTP id r6mr7471088lal.32.1397047949465; Wed, 09 Apr 2014 05:52:29 -0700 (PDT) Original-Sender: =?UTF-8?Q?Timo_Ter=C3=A4s?= In-Reply-To: <20140409155116.30ec723a@vostro> X-Mailer: Claws Mail 3.9.3 (GTK+ 2.24.23; i486-alpine-linux-uclibc) Xref: news.gmane.org gmane.linux.lib.musl.general:4852 Archived-At: On Wed, 9 Apr 2014 15:51:16 +0300 Timo Teras wrote: > On Wed, 9 Apr 2014 12:49:25 +0200 > u-igbb@aetey.se wrote: > > > On Wed, Apr 09, 2014 at 01:19:03PM +0300, Timo Teras wrote: > > > > const char *haystack = "abcde"; > > > > return(!memmem(haystack, 4, "cde", 3)); > > > > > > returns 1 (as I would expect it to) if linked against uclibc > > > > returns 0 if linked against musl > > > > (on ia32) > > > > I guess you misinterpreted the test code, there is a '!' which > > transforms a returned pointer (success) to 0 exit status in main() > > and vice versa. > > Right. Should have read it more carefully. Yes, looks like musl bug. > > Perhaps something like the following is in place: Wrong patch version. Should be as simple as: diff --git a/src/string/memmem.c b/src/string/memmem.c index 5211d75..1173020 100644 --- a/src/string/memmem.c +++ b/src/string/memmem.c @@ -139,6 +139,7 @@ void *memmem(const void *h0, size_t k, const void *n0, size_t l) /* Use faster algorithms for short needles */ h = memchr(h0, *n, k); if (!h || l==1) return (void *)h; + k -= h - (const unsigned char*)h0; if (l==2) return twobyte_memmem(h, k, n); if (l==3) return threebyte_memmem(h, k, n); if (l==4) return fourbyte_memmem(h, k, n);