Thread overview
[Issue 8334] New: find cannot handle close match at end of haystack in needle isn't bi-directional
Jul 01, 2012
Jonathan M Davis
Jul 02, 2012
Jonathan M Davis
Aug 20, 2012
Jonathan M Davis
July 01, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8334

           Summary: find cannot handle close match at end of haystack in
                    needle isn't bi-directional
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: jmdavisProg@gmx.com


--- Comment #0 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-07-01 15:08:02 PDT ---
This code

import std.array;
import std.algorithm;

void main()
{
    auto haystack = [1, 2, 3, 4, 1, 9, 12, 42];
    auto needle = filter!"true"([12, 42, 27]);
    assert(find(haystack, needle).empty);
}

results in this

core.exception.RangeError@std.algorithm(3255): Range violation
----------------
./q(_d_array_bounds+0x26) [0x436112]
./q() [0x42d9c9]
./q(int[] std.algorithm.find!("a == b", int[],
std.algorithm.filter!("true").filter!(int[]).filter.FilteredRange).find(int[],
std.algorithm.filter!("true").filter!(int[]).filter,
std.algorithm.filter!("true").filter!(int[]).filter.FilteredRange.FilteredRange
function(int[]))+0xc8) [0x42b748]
./q(_Dmain+0xc9) [0x42b149]
./q(extern (C) int rt.dmain2.main(int, char**).void runMain()+0x1c) [0x42c818]
./q(extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void
delegate())+0x2a) [0x42c192]
./q(extern (C) int rt.dmain2.main(int, char**).void runAll()+0x3b) [0x42c85f]
./q(extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void
delegate())+0x2a) [0x42c192]
./q(main+0xd1) [0x42c11d]
/lib/libc.so.6(__libc_start_main+0xf5) [0x7f25ecccc455]
----------------

If needle is an array rather than a filtered range, it's fine, and if the mismatch is before the end of the haystack, it's fine, but that particular overload of find cannot handle having the beginning of the needle match the end of the haystack when the needle is longer than the remainder of the haystack:

R1 find(alias pred = "a == b", R1, R2)(R1 haystack, R2 needle)
if (isRandomAccessRange!R1 && isForwardRange!R2 && !isBidirectionalRange!R2
        && is(typeof(binaryFun!pred(haystack.front, needle.front)) : bool))

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 02, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8334


Jonathan M Davis <jmdavisProg@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|jmdavisProg@gmx.com         |nobody@puremagic.com


--- Comment #1 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-07-01 18:18:08 PDT ---
https://github.com/D-Programming-Language/phobos/pull/659

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 20, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8334



--- Comment #2 from github-bugzilla@puremagic.com 2012-08-19 21:00:40 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/27912bb268325cfd27f2d6f649a5b30eef0ff5d7 Fix for issue# 8334.

https://github.com/D-Programming-Language/phobos/commit/47204076d83dfd66a7b4ba6beb773a661542f5ab Merge pull request #720 from jmdavis/8334

Fix for issue# 8334: find cannot handle close match at end of haystack in needle isn't bi-directional

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 20, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8334


Jonathan M Davis <jmdavisProg@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------