mailing list of musl libc
 help / color / mirror / code / Atom feed
* memmem() - is it correct?
@ 2014-04-09 10:08 u-igbb
  2014-04-09 10:19 ` Timo Teras
  0 siblings, 1 reply; 6+ messages in thread
From: u-igbb @ 2014-04-09 10:08 UTC (permalink / raw)
  To: musl

A test case adapted from elsewhere:
----
#include <string.h>

main(){
  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)

Any comments?
Rune



^ permalink raw reply	[flat|nested] 6+ messages in thread
* Re: memmem() - is it correct?
@ 2014-04-09 12:14 u-igbb
  0 siblings, 0 replies; 6+ messages in thread
From: u-igbb @ 2014-04-09 12:14 UTC (permalink / raw)
  To: musl

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)

> musl looks correct to me. "abcde" is five bytes. You test for 4 bytes

I am testing for 3 bytes "cde" inside 4 bytes "abcd", this should not
be successful.

> so it's infact searching from haystack equivalent of "abcd".

Exactly. It does _not_ contain "cde". This should return NULL
from the memmem() and hence 1 from main().

> I'd say uclibc is off-by-one, and broken.

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.

Rune



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-04-10  1:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-09 10:08 memmem() - is it correct? 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
2014-04-10  1:15         ` Rich Felker
2014-04-09 12:14 u-igbb

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).