solang
solang copied to clipboard
Pointer to uninitialized External Function struct should not be null
This contract causes an access violation in Solana's mock VM, because fun is a null pointer.
contract C {
function test(uint256 newAddress, bytes4 newSelector) public view returns (bytes4, address) {
function() external fun;
address myAddr = address(newAddress);
assembly {
fun.selector := myAddr
fun.address := newAddress
}
return (fun.selector, fun.address);
}
}
This won't even compile with solc:
Error: Explicit type conversion not allowed from "uint256" to "address".
--> bug.sol:7:26:
|
7 | address myAddr = address(newAddress);
| ^^^^^^^^^^^^^^^^^^^
This won't even compile with
solc:Error: Explicit type conversion not allowed from "uint256" to "address". --> bug.sol:7:26: | 7 | address myAddr = address(newAddress); | ^^^^^^^^^^^^^^^^^^^
That's because an address is 20 bytes on ethereum. I think this will work:
contract C {
function test(uint160 newAddress, bytes4 newSelector) public view returns (bytes4, address) {
function() external fun;
address myAddr = address(newAddress);
assembly {
fun.selector := myAddr
fun.address := newAddress
}
return (fun.selector, fun.address);
}
}
Of course, maybe next time I should read the contract first