Skip to content

Default elements when resizing arrays by assigning to length #97

Open
@hajduakos

Description

@hajduakos

When we resize an array by assigning to length, the new elements are not set to their default value (except in the constructor). We should give at least give a warning (bug) as long as it is not implemented (enhancement).

pragma solidity >=0.5.0;

contract Issue097 {
    int[] arr;

    constructor() public {
        arr.length += 1;
        assert(arr[arr.length-1] == 0);
    }

    function() external payable {
        arr.length += 1;
        assert(arr[arr.length-1] == 0);
    }
}
$ solc-verify.py issues/Issue097.sol 
Issue097::[constructor]: OK
Issue097::[fallback]: ERROR
 - issues/Issue097.sol:13:9: Assertion might not hold.
Errors were found by the verifier.

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions