From 9e2b26e046adf56f48f73afcd982984d9f697cd1 Mon Sep 17 00:00:00 2001 From: aathan Date: Tue, 29 Mar 2022 13:48:49 -0700 Subject: [PATCH] Clarify the reason for the memory-unsafe assembly example being unsafe --- docs/assembly.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/assembly.rst b/docs/assembly.rst index 0876229b1..70c4a458d 100644 --- a/docs/assembly.rst +++ b/docs/assembly.rst @@ -313,7 +313,8 @@ Furthermore, if the assembly block assigns to Solidity variables in memory, you the Solidity variables only access these memory ranges. Since this is mainly about the optimizer, these restrictions still need to be followed, even if the assembly block -reverts or terminates. As an example, the following assembly snippet is not memory safe: +reverts or terminates. As an example, the following assembly snippet is not memory safe, because the value of +``returndatasize()`` may exceed the 64 byte scratch space: .. code-block:: solidity @@ -322,7 +323,8 @@ reverts or terminates. As an example, the following assembly snippet is not memo revert(0, returndatasize()) } -But the following is: +On the other hand, the following code *is* memory safe, because memory beyond the location pointed to by the +free memory pointer can safely be used as temporary scratch space: .. code-block:: solidity