Array delete nullification detector#
Name: array-delete-nullification
Using delete
on array elements only nullifies the element instead of removing it from the array.
This can lead to confusion if developers expect the array to be shortened.
Example#
- The
delete
statement setsnumbers[index]
to 0 but does not remove it from the array or reduce the array length.
False positives#
Reports may be intentional when implementing "soft delete" patterns, managing fixed-size arrays, or clearing sensitive data while preserving array structure.
False negatives#
May miss cases where array elements are nullified through direct assignment or complex expressions.
Best practices#
To actually remove an element from an array, use "swap and pop" for unordered arrays:
function removeElement(uint index) public {
myArray[index] = myArray[myArray.length - 1];
myArray.pop();
}
Parameters#
The detector does not accept any additional parameters. ```