DIP 1025--Dynamic Arrays Only Shrink, Never Grow--Community Review Round 1
Jab
jab_293 at gmall.com
Tue Nov 12 17:25:06 UTC 2019
On Tuesday, 12 November 2019 at 15:54:22 UTC, John Colvin wrote:
> *The author should explain what previously impossible/unsafe
> code can now be made possible/safe given the proposed change.*
Looking at the examples again, do they even show memory
corruption?
This would be a memory leak, not memory corruption:
int[] slice = cast(int*)malloc(10 * int.sizeof)[0 .. 10];
slice ~= 1;
free(slice.ptr); // Oops!
This doesn't show memory corruption either, its a potential logic
bug as it doesn't consider a side effect of array concatenation.
enum { dead, alive }
int[] cat = new int[6];
cat[5] = alive;
int[] b = cat;
b ~= 1; // may or may not move b to new location
b[5] = dead; // indeterminate whether cat[5] is dead or alive
Neither of these examples are pertinent to @safe, which is aimed
at reducing/removing memory corruption.
This would be a more relevant problem for @safe:
int[] slice = cast(int*)malloc(10 * int.sizeof)[0 .. 10];
free(slice.ptr);
slice ~= 1; // use after free
As far as I'm aware none of the current previous DIPs resolve
this do they?
More information about the Digitalmars-d
mailing list