From a885cbd30c55dd4cf06aecb8b66cfd2ed19bf3e2 Mon Sep 17 00:00:00 2001 From: Yuvraj Rodage Date: Wed, 19 Apr 2023 13:26:17 +0530 Subject: [PATCH] padded free memory pointer --- contracts/TypedMemView.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/TypedMemView.sol b/contracts/TypedMemView.sol index ffd400e..8fb8392 100644 --- a/contracts/TypedMemView.sol +++ b/contracts/TypedMemView.sol @@ -711,7 +711,7 @@ library TypedMemView { unsafeCopyTo(memView, ptr + 0x20); assembly { // solium-disable-previous-line security/no-inline-assembly - mstore(0x40, add(add(ptr, _len), 0x20)) // write new unused pointer + mstore(0x40, add(add(ptr, add(_len, 31)), 0x20)) // write new unused pointer mstore(ptr, _len) // write len of new array (in bytes) } } @@ -795,7 +795,7 @@ library TypedMemView { // store the legnth mstore(ptr, _written) // new pointer is old + 0x20 + the footprint of the body - mstore(0x40, add(add(ptr, _footprint), 0x20)) + mstore(0x40, add(add(ptr, add(_footprint, 0x1f)), 0x20)) ret := ptr } }