[Issue 22673] New: .array of a range with length preallocates without checking if the length was lying or not.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jan 13 22:34:08 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=22673
Issue ID: 22673
Summary: .array of a range with length preallocates without
checking if the length was lying or not.
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: maxhaton at gmail.com
```
struct Range
{
enum size_t length = 100;
enum size_t evilRealLength = 50;
size_t idx;
Type front()
{
return Type(0);
}
bool empty()
{
return idx == evilRealLength;
}
void popFront()
{
++idx;
}
}
```
This will allocate 100 `Type`s but only 50 will be touched, what happens if
those later ones get destructed?
--
More information about the Digitalmars-d-bugs
mailing list