[Issue 11576] New: std.algorithm.remove!(SwapStrategy.unstable) overruns array bounds
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Nov 21 19:15:11 PST 2013
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 at puremagic.com
ReportedBy: hsteoh at quickfur.ath.cx
--- Comment #0 from hsteoh at 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 at 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: -------
More information about the Digitalmars-d-bugs
mailing list