Closed MoMannn closed 3 years ago
This is a revised version that works in 0.8.0
function uint2str(
uint256 _i
)
internal
pure
returns (string memory str)
{
if (_i == 0)
{
return "0";
}
uint256 j = _i;
uint256 length;
while (j != 0)
{
length++;
j /= 10;
}
bytes memory bstr = new bytes(length);
uint256 k = length;
j = _i;
while (j != 0)
{
bstr[--k] = bytes1(uint8(48 + j % 10));
j /= 10;
}
str = string(bstr);
}
It works perfectly with in 0.8.0. Thank you very much!!!
https://github.com/provable-things/ethereum-api/blob/9f34daaa550202c44f48cdee7754245074bde65d/provableAPI_0.6.sol#L1028
Looks like it fails because of 0.8 math underflow/overflow detection in [k--].