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
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/8ba7ce59ba4bbeb1e7f45fb34ecff2a02930aad9 Fix issue 13619 - array capacity not updated when changing length https://github.com/dlang/phobos/commit/9872247505c8a62e87bb97010084406c051eed2f Merge pull request #5267 from byebye/issue_13619 Fix issue 13619 - array capacity not updated when changing length merged-on-behalf-of: Jack Stouffer <[email protected]>
Comment #6 by github-bugzilla — 2017-03-22T12:22:34Z
Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/8ba7ce59ba4bbeb1e7f45fb34ecff2a02930aad9 Fix issue 13619 - array capacity not updated when changing length https://github.com/dlang/phobos/commit/9872247505c8a62e87bb97010084406c051eed2f Merge pull request #5267 from byebye/issue_13619
Comment #7 by github-bugzilla — 2017-08-07T12:26:26Z
Commits pushed to newCTFE at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/8ba7ce59ba4bbeb1e7f45fb34ecff2a02930aad9 Fix issue 13619 - array capacity not updated when changing length https://github.com/dlang/phobos/commit/9872247505c8a62e87bb97010084406c051eed2f Merge pull request #5267 from byebye/issue_13619
Comment #8 by github-bugzilla — 2018-01-05T13:27:46Z
Commits pushed to dmd-cxx at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/8ba7ce59ba4bbeb1e7f45fb34ecff2a02930aad9 Fix issue 13619 - array capacity not updated when changing length https://github.com/dlang/phobos/commit/9872247505c8a62e87bb97010084406c051eed2f Merge pull request #5267 from byebye/issue_13619