www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11576] New: std.algorithm.remove!(SwapStrategy.unstable) overruns array bounds

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11576

           Summary: std.algorithm.remove!(SwapStrategy.unstable) overruns
                    array bounds
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: hsteoh quickfur.ath.cx


--- Comment #0 from hsteoh quickfur.ath.cx 2013-11-21 19:15:09 PST ---
CODE:
-------
import std.algorithm, std.stdio;

void main() {
    auto arr = [1,2,3,4];

    arr = arr.remove!(SwapStrategy.unstable)(1); // OK
    assert(arr == [1,4,3]);

    arr = arr.remove!(SwapStrategy.unstable)(1); // OK
    assert(arr == [1,3]);

    arr = arr.remove!(SwapStrategy.unstable)(1); // NG
    assert(arr == [1]);
}
-------

OUTPUT:
-------
core.exception.RangeError std.algorithm(8139): Range violation
----------------
./test(_d_array_bounds+0x26) [0x43e84e]
./test() [0x438b12]
./test(pure nothrow  safe int[]
std.algorithm.__T6removeVE3std9algorithm12SwapStrategy0TAiTiZ.remove(int[],
int)+0xab) [0x42e11b]
./test(_Dmain+0x154) [0x42dde4]
./test(void rt.dmain2._d_run_main(int, char**, extern (C) int
function(char[][])*).runAll().void __lambda1()+0x18) [0x435b98]
./test(void rt.dmain2._d_run_main(int, char**, extern (C) int
function(char[][])*).tryExec(scope void delegate())+0x2a) [0x435af2]
./test(void rt.dmain2._d_run_main(int, char**, extern (C) int
function(char[][])*).runAll()+0x30) [0x435b58]
./test(void rt.dmain2._d_run_main(int, char**, extern (C) int
function(char[][])*).tryExec(scope void delegate())+0x2a) [0x435af2]
./test(_d_run_main+0x1a3) [0x435a73]
./test(main+0x17) [0x433d67]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x7f17abe1d995]
-------

The range violation occurs at the line marked // NG.

This bug consistently happens every time you attempt to remove the last element
from an array. In earlier versions of Phobos, this bug does not occur.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 21 2013
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11576



--- Comment #1 from hsteoh quickfur.ath.cx 2013-11-21 19:15:49 PST ---
P.S. This is on Phobos git HEAD. I haven't checked the latest release to see if
it also happens there.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 21 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11576


hsteoh quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #2 from hsteoh quickfur.ath.cx 2013-11-21 19:37:11 PST ---
https://github.com/D-Programming-Language/phobos/pull/1710

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 21 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11576



--- Comment #3 from github-bugzilla puremagic.com 2013-11-22 00:31:41 PST ---
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/c1ce350db96e135c1a81a702f2f8913a139f13fc
Fix issue 11576.

https://github.com/D-Programming-Language/phobos/commit/b6add96a2ba1a37ae231ad5ead01411bed7e9c97
Merge pull request #1710 from quickfur/issue11576

Fix issue 11576.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 22 2013
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11576


hsteoh quickfur.ath.cx changed:

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


--- Comment #4 from hsteoh quickfur.ath.cx 2013-11-22 07:39:06 PST ---
Confirmed fixed in git HEAD.

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