I was reading solidity documentation about when an assert-style exception is generated. In the 6th point it says:
"If you call a zero-initialized variable of internal function type."
I don't understand it. Can someone give me an example?
I was reading solidity documentation about when an assert-style exception is generated. In the 6th point it says:
"If you call a zero-initialized variable of internal function type."
I don't understand it. Can someone give me an example?
Variables can contain function pointers. If you leave them uninitialized and then try to call them, the call will fail because the variable was zero-initialized and therefore it does not contain a pointer to a callable function. Example:
function b(int x, int y) internal pure returns (int)
{
return x * y;
}
function test1() external pure returns (int)
{
// Variable containing a function pointer
function (int, int) internal pure returns (int) funcPtr;
funcPtr = b;
// This call to funcPtr will succeed
return funcPtr(4, 5);
}
function test2() external pure returns (int)
{
// Variable containing a function pointer
function (int, int) internal pure returns (int) funcPtr;
// This call will fail because funcPtr is still a zero-initialized function pointer
return funcPtr(4, 5);
}