Thread overview
[Issue 22673] .array of a range with length preallocates without checking if the length was lying or not.
4 days ago
Adam D. Ruppe
4 days ago
mhh
4 days ago
Adam D. Ruppe
4 days ago
mhh
3 days ago
Dlang Bot
4 days ago
https://issues.dlang.org/show_bug.cgi?id=22673

Adam D. Ruppe <destructionator@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |destructionator@gmail.com

--- Comment #1 from Adam D. Ruppe <destructionator@gmail.com> ---
The others will be in the .init state, which should mean the destructor is a no-op on them.

--
4 days ago
https://issues.dlang.org/show_bug.cgi?id=22673

--- Comment #2 from mhh <maxhaton@gmail.com> ---
The array allocated is uninitialized.
```
auto result = (() @trusted => uninitializedArray!(Unqual!E[])(length))();
```

--
4 days ago
https://issues.dlang.org/show_bug.cgi?id=22673

--- Comment #3 from Adam D. Ruppe <destructionator@gmail.com> ---
ah i see yeah that's good good.

the fix would prolly be to just bit some init over and slice it off then at the end

--
4 days ago
https://issues.dlang.org/show_bug.cgi?id=22673

--- Comment #4 from mhh <maxhaton@gmail.com> ---
(In reply to Adam D. Ruppe from comment #3)
> ah i see yeah that's good good.
> 
> the fix would prolly be to just bit some init over and slice it off then at the end

I kind of think this should actually error or throw, because I think it's a bit iffy letting these kinds of things fester. There's a wider problem though, if something throws when filling the array up then it will be finalized with (what must be assumed to be, even if it is zero) junk. For that the fix I have is to just write T.init into the memory before passing the exception (this might be a case to catch Throwable) up.

Slightly painful to test, I can't quite get the GC to collect before I try and check all the destructions were valid. I might have to put an assert in the destructor (bitch to debug if it ever breaks)

--
3 days ago
https://issues.dlang.org/show_bug.cgi?id=22673

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #5 from Dlang Bot <dlang-bot@dlang.rocks> ---
@maxhaton created dlang/phobos pull request #8359 "Fixes issues 22185, 22673" fixing this issue:

- Fixes issues 22185, 22673

https://github.com/dlang/phobos/pull/8359

--