diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-08-11 00:47:35 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-08-11 00:47:35 +0800 |
commit | 9358001ba4074d94d9daa566d225e1f8b2305009 (patch) | |
tree | a149408a7be68fc4d391aed0b9a36b14f209c39b | |
parent | 34503d98d7d95fc3a55a60be854809524c1f204e (diff) | |
download | dexon-solidity-9358001ba4074d94d9daa566d225e1f8b2305009.tar dexon-solidity-9358001ba4074d94d9daa566d225e1f8b2305009.tar.gz dexon-solidity-9358001ba4074d94d9daa566d225e1f8b2305009.tar.bz2 dexon-solidity-9358001ba4074d94d9daa566d225e1f8b2305009.tar.lz dexon-solidity-9358001ba4074d94d9daa566d225e1f8b2305009.tar.xz dexon-solidity-9358001ba4074d94d9daa566d225e1f8b2305009.tar.zst dexon-solidity-9358001ba4074d94d9daa566d225e1f8b2305009.zip |
Use temporary variable for sum example
-rw-r--r-- | docs/assembly.rst | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/docs/assembly.rst b/docs/assembly.rst index 377a6530..bdb708a9 100644 --- a/docs/assembly.rst +++ b/docs/assembly.rst @@ -104,19 +104,21 @@ you really know what you are doing. let len := mload(_data) // Skip over the length field. - _data := add(_data, 0x20) + // + // Keep temporary variable so it can be incremented in place. + // + // NOTE: incrementing _data would result in an unusable + // _data variable after this assembly block + let data := add(_data, 0x20) // Iterate until the bound is not met. for - { let end := add(_data, len) } - lt(_data, end) - { _data := add(_data, 0x20) } + { let end := add(data, len) } + lt(data, end) + { data := add(data, 0x20) } { - o_sum := add(o_sum, mload(_data)) + o_sum := add(o_sum, mload(data)) } - - // NOTE: after this point it is not safe to use _data in Solidity code - // because its offsets are in an invalid position } } } |