From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/4851 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:51:16 +0300 Message-ID: <20140409155116.30ec723a@vostro> References: <20140409100840.GD21662@example.net> <20140409131903.70876825@vostro> <20140409104925.GE21662@example.net> 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 1397047801 9341 80.91.229.3 (9 Apr 2014 12:50:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 9 Apr 2014 12:50:01 +0000 (UTC) Cc: musl@lists.openwall.com To: u-igbb@aetey.se Original-X-From: musl-return-4855-gllmg-musl=m.gmane.org@lists.openwall.com Wed Apr 09 14:49:55 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 1WXrwx-00062h-2J for gllmg-musl@plane.gmane.org; Wed, 09 Apr 2014 14:49:55 +0200 Original-Received: (qmail 3880 invoked by uid 550); 9 Apr 2014 12:49:54 -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 3872 invoked from network); 9 Apr 2014 12:49:54 -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=CYg0FJCoegOI480fg1S+O9vXhYTMl8CLrcUuYqGLbyE=; b=cC4X9HJHMf1Mwd3BPGRZrk0v2W/JxCxtrNhkoI2IT3y0AY5U1kjn5tsHB2+hRl53Cm k7uyXInoARXPC1Zd6QGLqqYoJzIoZ8KhXDbzNhSymhMwvhmU1uDlA6uCy0m4ao43CeWr neiRnAFHEopF9p0Xbk09S+zUDVfJS2lPPPELSpiAxKgrDN/RhkDhrePUmquitm3FxZcl X75ObkGnUL3LZFSoYHBB4Pf47Njnt51WlO//4T3E+oxow1nC9PeQRY9sH8eHtwBVxkgR SmeiAZdGmXvDvxE49rrXEz3J5XZv/mIaoPluEghDmObt38xY25YpPtN0DsquihzeSNRP 31Fw== X-Received: by 10.112.106.40 with SMTP id gr8mr7105294lbb.0.1397047782423; Wed, 09 Apr 2014 05:49:42 -0700 (PDT) Original-Sender: =?UTF-8?Q?Timo_Ter=C3=A4s?= In-Reply-To: <20140409104925.GE21662@example.net> X-Mailer: Claws Mail 3.9.3 (GTK+ 2.24.23; i486-alpine-linux-uclibc) Xref: news.gmane.org gmane.linux.lib.musl.general:4851 Archived-At: 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: diff --git a/src/string/memmem.c b/src/string/memmem.c index 5211d75..0594fea 100644 --- a/src/string/memmem.c +++ b/src/string/memmem.c @@ -138,7 +138,9 @@ 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; + if (!h) return 0; + if (l==1) return (void *)h; + k -= h - 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);