[Issue 22673] .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
Fri Jan 14 01:08:15 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=22673

--- Comment #4 from mhh <maxhaton at 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)

--


More information about the Digitalmars-d-bugs mailing list