D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 13425 - DList.linearRemove on last element returns non-empty range
Summary: DList.linearRemove on last element returns non-empty range
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-05 17:56 UTC by ryan
Modified: 2014-09-08 20:20 UTC (History)
1 user (show)

See Also:


Attachments
The example above, in case you care to test it (274 bytes, text/x-dsrc)
2014-09-05 17:56 UTC, ryan
Details

Note You need to log in before you can comment on or make changes to this issue.
Description ryan 2014-09-05 17:56:54 UTC
Created attachment 1417 [details]
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 github-bugzilla 2014-09-08 20:20:32 UTC
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...