Bug 13619 – std.container.array capacity not updated when length increases
Status
RESOLVED
Resolution
FIXED
Severity
trivial
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-10-15T08:23:41Z
Last change time
2018-01-05T13:27:46Z
Keywords
trivial
Assigned to
No Owner
Creator
thedeemon
Comments
Comment #0 by dlang — 2014-10-15T08:23:41Z
import std.container;
void main() {
Array!int a; // empty Array
a.length = 10;
// now payload is allocated, length is set to 10, but capacity is still 0!
// try to append a value
a ~= 1; // runtime error (assertion: capacity < length !)
}
Fix is trivial, Array.Payload.length setter must update _capacity field when it reallocates data.
Comment #1 by monarchdodra — 2014-10-18T17:42:21Z
That's not fixed yet !?
Comment #2 by safety0ff.bugz — 2014-10-21T08:33:02Z
I think the bug you reported is not valid.
However, there is a bug when using length to shorten the array:
import std.container;
void main() {
Array!int a; // empty Array
a.length = 10; // a contains 10 default ints
a.length = 9; // Remove one, should have capacity > 0
assert(a.capacity > 0);
}
Comment #3 by dlang — 2014-10-21T11:02:26Z
Why do you think it's not valid?
It does throw runtime error and capacity is wrong after setting the length.
http://dpaste.dzfl.pl/b10858af2a56
Comment #4 by safety0ff.bugz — 2014-10-22T01:23:46Z
Ah, I misinterpreted the meaning of the capacity (unused capacity vs total capacity.)
Perhaps the title should be "std.container.array capacity not updated when changing length" or something like that since it's not specific to increasing length.
Comment #5 by github-bugzilla — 2017-03-11T20:00:27Z