mailing list of musl libc
 help / color / mirror / code / Atom feed
* src/string/wcsstr.c doesn't work
@ 2014-04-18 16:41 Yves Bastide
  2014-04-18 21:49 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: Yves Bastide @ 2014-04-18 16:41 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 331 bytes --]

Hi,

twoway_wcsstr doesn't (always) work with periodic needles. With the
attached example

haystack = L"playing play play play always";
needle = L"play play play";

mem0 = 9, ms = 3; thus, after a left-half mismatch on "playing", mem is 9 and
    for (k = ms + 1; k>mem && n[k - 1] == h[k - 1]; k--);
terminates immediately.

yves

[-- Attachment #2: test_wcsstr.c --]
[-- Type: text/x-csrc, Size: 283 bytes --]

#include <wchar.h>
#include <assert.h>

int main(int argc, char* argv[])
{
        wchar_t const *haystack = L"playing play play play always";
        wchar_t const *needle = L"play play play";

        wchar_t * p = wcsstr(haystack, needle);

        assert(p);
        return 0;
}

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

* Re: src/string/wcsstr.c doesn't work
  2014-04-18 16:41 src/string/wcsstr.c doesn't work Yves Bastide
@ 2014-04-18 21:49 ` Rich Felker
  0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2014-04-18 21:49 UTC (permalink / raw)
  To: musl

On Fri, Apr 18, 2014 at 06:41:46PM +0200, Yves Bastide wrote:
> Hi,
> 
> twoway_wcsstr doesn't (always) work with periodic needles. With the
> attached example
> 
> haystack = L"playing play play play always";
> needle = L"play play play";
> 
> mem0 = 9, ms = 3; thus, after a left-half mismatch on "playing", mem is 9 and
>     for (k = ms + 1; k>mem && n[k - 1] == h[k - 1]; k--);
> terminates immediately.

Thanks! Immediate termination of this loop is correct, but the
subsequent conditional should have been treating it as success rather
than failure. Fix committed.

Rich


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

end of thread, other threads:[~2014-04-18 21:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-18 16:41 src/string/wcsstr.c doesn't work Yves Bastide
2014-04-18 21:49 ` Rich Felker

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