aboutsummaryrefslogtreecommitdiffstats
path: root/contracts/libs
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-12-19 03:36:05 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-12-19 05:36:05 +0800
commitd2a4fd570622de34a3d8e8a25735b025e3ac5f77 (patch)
treea93c3ca211b3401f5de7c3b4ef23dcc8efdddea4 /contracts/libs
parentafe200c4e1bd76d5f2dbfcb7898ca025a7bb3dd6 (diff)
downloaddexon-sol-tools-d2a4fd570622de34a3d8e8a25735b025e3ac5f77.tar
dexon-sol-tools-d2a4fd570622de34a3d8e8a25735b025e3ac5f77.tar.gz
dexon-sol-tools-d2a4fd570622de34a3d8e8a25735b025e3ac5f77.tar.bz2
dexon-sol-tools-d2a4fd570622de34a3d8e8a25735b025e3ac5f77.tar.lz
dexon-sol-tools-d2a4fd570622de34a3d8e8a25735b025e3ac5f77.tar.xz
dexon-sol-tools-d2a4fd570622de34a3d8e8a25735b025e3ac5f77.tar.zst
dexon-sol-tools-d2a4fd570622de34a3d8e8a25735b025e3ac5f77.zip
Added documentation to `LibAddressArray.append` and switched `if` to `require` smt
Diffstat (limited to 'contracts/libs')
-rw-r--r--contracts/libs/contracts/libs/LibAddressArray.sol11
1 files changed, 10 insertions, 1 deletions
diff --git a/contracts/libs/contracts/libs/LibAddressArray.sol b/contracts/libs/contracts/libs/LibAddressArray.sol
index db76ddedb..ccae2ac5f 100644
--- a/contracts/libs/contracts/libs/LibAddressArray.sol
+++ b/contracts/libs/contracts/libs/LibAddressArray.sol
@@ -45,11 +45,20 @@ library LibAddressArray {
addressArrayEndPtr := add(addressArray, addressArrayMemSizeInBytes)
}
+ // Cases for `freeMemPtr`:
+ // `freeMemPtr` == `addressArrayEndPtr`: Nothing occupies memory after `addressArray`
+ // `freeMemPtr` > `addressArrayEndPtr`: Some value occupies memory after `addressArray`
+ // `freeMemPtr` < `addressArrayEndPtr`: Memory has not been managed properly.
+ require(
+ freeMemPtr >= addressArrayEndPtr,
+ "INVALID_FREE_MEMORY_PTR"
+ );
+
// If free memory begins at the end of `addressArray`
// then we can append `addressToAppend` directly.
// Otherwise, we must copy the array to free memory
// before appending new values to it.
- if (freeMemPtr != addressArrayEndPtr) {
+ if (freeMemPtr > addressArrayEndPtr) {
LibBytes.memCopy(freeMemPtr, addressArrayBeginPtr, addressArrayMemSizeInBytes);
assembly {
addressArray := freeMemPtr