Warn about changes to in-parameters of array type
If changes are made to an array in-parameter those change obviously effect the caller side, but length changes can't be propagated back to the caller side, leading to memory leak or double free.
There should be a warning for such an access on in-parameter of array type.
void increase (string[] array) {
assert (array.length == 2);
array.resize (array.length + 1);
array[array.length - 1] = "new";
assert (array.length == 3);
}
void decrease (string[] array) {
assert (array.length == 2);
array[array.length - 1] = null;
array.resize (array.length - 1);
assert (array.length == 1);
}
void main () {
{
string[] array = {"foo", "bar"};
increase (array);
assert (array.length == 2);
// Memory leak
assert (array[2] == "new");
}
{
string[] array = {"foo", "bar"};
decrease (array);
assert (array.length == 2);
// Double free
assert (array[1] == "bar");
}
}
Edited by Rico Tzschichholz