Bug 13425 – DList.linearRemove on last element returns non-empty range

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2014-09-05T17:56:00Z
Last change time
2014-09-08T20:20:33Z
Assigned to
nobody
Creator
ryan

Attachments

IDFilenameSummaryContent-TypeSize
1417dlist.dThe example above, in case you care to test ittext/x-dsrc274

Comments

Comment #0 by ryan — 2014-09-05T17:56:54Z
Created attachment 1417 The example above, in case you care to test it If a range refers to the last element in a DList, I would expect linearRemove to return an empty range. Instead it returns a non-empty range that appears to access memory outside the list's bounds. Example: auto list = DList!int([1,2,3,4,5]); auto r = list[].drop(4); // r is a view of the last element of list assert(r.front == 5 && r.walkLength == 1); r = list.linearRemove(r.take(1)); assert(r.empty); // fails
Comment #1 by github-bugzilla — 2014-09-08T20:20:32Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/d10fea94d5ba6cb18ba98cb59ecbee21fef3dc82 Fix issue 13425 - DList.linearRemove on last... ...element returns non-empty range. The main issue is that DList.Range is implemented in terms of "first and last" as opposed to "first and past last", which means you have to special-case empty ranges. The fix is to do the same thing as in `opSlice`, and to explicitly initialize a null Range when it is empty. https://github.com/D-Programming-Language/phobos/commit/320d5e7e4714eb70cec641ef67f7ea9cd61b8eaa Merge pull request #2497 from monarchdodra/DListRemove Fix issue 13425 - DList.linearRemove on last...