malloc and buffer overflow attacks

Adam Ruppe destructionator at
Fri Dec 31 00:34:46 UTC 2021

On Friday, 31 December 2021 at 00:15:48 UTC, Adam Ruppe wrote:
> T[] p = (cast(T*)malloc(len * T.sizeof))[0 .. len * T.sizepf];

eeeek, I did it wrong!

Should be either [0 .. len] on the slice or do the cast on the 
outside instead of inside of parens.

This is why just using `new` is the best of all!

More information about the Digitalmars-d mailing list