mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Timo Teras <timo.teras@iki.fi>
To: u-igbb@aetey.se
Cc: musl@lists.openwall.com
Subject: Re: memmem() - is it correct?
Date: Wed, 9 Apr 2014 15:54:03 +0300	[thread overview]
Message-ID: <20140409155403.2d4060a0@vostro> (raw)
In-Reply-To: <20140409155116.30ec723a@vostro>

On Wed, 9 Apr 2014 15:51:16 +0300
Timo Teras <timo.teras@iki.fi> 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);


  reply	other threads:[~2014-04-09 12:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-09 10:08 u-igbb
2014-04-09 10:19 ` Timo Teras
     [not found]   ` <20140409104925.GE21662@example.net>
2014-04-09 12:51     ` Timo Teras
2014-04-09 12:54       ` Timo Teras [this message]
2014-04-10  1:15         ` Rich Felker
2014-04-09 12:14 u-igbb

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140409155403.2d4060a0@vostro \
    --to=timo.teras@iki.fi \
    --cc=musl@lists.openwall.com \
    --cc=u-igbb@aetey.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).