Skip to content

Commit d880879

Browse files
authored
fix stdstorage return handling (#29)
1 parent 4bfb08b commit d880879

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/stdlib.sol

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,14 @@ library stdStorage {
190190
}
191191
// store
192192
vm_std_store.store(who, reads[i], bytes32(hex"1337"));
193+
bool success;
194+
bytes memory rdat;
193195
{
194-
(, bytes memory rdat) = who.staticcall(cald);
196+
(success, rdat) = who.staticcall(cald);
195197
fdat = bytesToBytes32(rdat, 32*field_depth);
196198
}
197199

198-
if (fdat == bytes32(hex"1337")) {
200+
if (success && fdat == bytes32(hex"1337")) {
199201
// we found which of the slots is the actual one
200202
emit SlotFound(who, fsig, keccak256(abi.encodePacked(ins, field_depth)), uint256(reads[i]));
201203
self.slots[who][fsig][keccak256(abi.encodePacked(ins, field_depth))] = uint256(reads[i]);
@@ -304,7 +306,8 @@ library stdStorage {
304306
function bytesToBytes32(bytes memory b, uint offset) public pure returns (bytes32) {
305307
bytes32 out;
306308

307-
for (uint i = 0; i < 32; i++) {
309+
uint256 max = b.length > 32 ? 32 : b.length;
310+
for (uint i = 0; i < max; i++) {
308311
out |= bytes32(b[offset + i] & 0xFF) >> (i * 8);
309312
}
310313
return out;

0 commit comments

Comments
 (0)