From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/4862 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: memmem() - is it correct? Date: Wed, 9 Apr 2014 21:15:32 -0400 Message-ID: <20140410011532.GM26358@brightrain.aerifal.cx> References: <20140409100840.GD21662@example.net> <20140409131903.70876825@vostro> <20140409104925.GE21662@example.net> <20140409155116.30ec723a@vostro> <20140409155403.2d4060a0@vostro> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1397092553 9239 80.91.229.3 (10 Apr 2014 01:15:53 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 10 Apr 2014 01:15:53 +0000 (UTC) Cc: u-igbb@aetey.se To: musl@lists.openwall.com Original-X-From: musl-return-4866-gllmg-musl=m.gmane.org@lists.openwall.com Thu Apr 10 03:15:47 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 1WY3ak-0000Af-UK for gllmg-musl@plane.gmane.org; Thu, 10 Apr 2014 03:15:47 +0200 Original-Received: (qmail 17697 invoked by uid 550); 10 Apr 2014 01:15:44 -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 17685 invoked from network); 10 Apr 2014 01:15:44 -0000 Content-Disposition: inline In-Reply-To: <20140409155403.2d4060a0@vostro> User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:4862 Archived-At: On Wed, Apr 09, 2014 at 03:54:03PM +0300, Timo Teras wrote: > 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); Thanks! Committed. Rich