From 9358001ba4074d94d9daa566d225e1f8b2305009 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 10 Aug 2017 17:47:35 +0100 Subject: Use temporary variable for sum example --- docs/assembly.rst | 18 ++++++++++-------- 1 file 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 } } } -- cgit