Created
November 20, 2018 03:37
-
-
Save tim-cotten/5776fe9b86c333d4c3a52727f91e9958 to your computer and use it in GitHub Desktop.
Solidity: An example implementation of why not to trust `var i = 0` in for loops
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//sol Infinite8BitForLoop | |
// @authors | |
// Tim Cotten <tim@cotten.io> (https://blog.cotten.io) | |
// An example implementation of why not to trust `var i = 0` in for loops | |
// Input to the test function above 255 results in an infinite loop | |
pragma solidity ^0.4.0; | |
contract Infinite8BitForLoop { | |
function test(uint256 x) public pure returns(uint256) | |
{ | |
uint256 total = 0; | |
for (var i = 0; i < x; i++) { | |
total++; | |
} | |
return total; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment