aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-04-16 23:43:40 +0800
committerchriseth <c@ethdev.com>2015-04-17 19:27:31 +0800
commit5622364a98102574f04019e2f1041d54d2d04984 (patch)
tree6cd948d13e12a5a15c2fa2ed9af8dd1569739e88
parent6e5de4832da7a3c2fdbc87b71523ac671083d9c0 (diff)
downloaddexon-solidity-5622364a98102574f04019e2f1041d54d2d04984.tar
dexon-solidity-5622364a98102574f04019e2f1041d54d2d04984.tar.gz
dexon-solidity-5622364a98102574f04019e2f1041d54d2d04984.tar.bz2
dexon-solidity-5622364a98102574f04019e2f1041d54d2d04984.tar.lz
dexon-solidity-5622364a98102574f04019e2f1041d54d2d04984.tar.xz
dexon-solidity-5622364a98102574f04019e2f1041d54d2d04984.tar.zst
dexon-solidity-5622364a98102574f04019e2f1041d54d2d04984.zip
Fix for signed integers in storage.
-rw-r--r--LValue.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/LValue.cpp b/LValue.cpp
index 02e6cbca..68428a0b 100644
--- a/LValue.cpp
+++ b/LValue.cpp
@@ -107,6 +107,11 @@ void StorageItem::retrieveValue(SourceLocation const&, bool _remove) const
<< u256(0x100) << eth::Instruction::EXP << eth::Instruction::SWAP1 << eth::Instruction::DIV;
if (m_dataType.getCategory() == Type::Category::FixedBytes)
m_context << (u256(0x1) << (256 - 8 * m_dataType.getStorageBytes())) << eth::Instruction::MUL;
+ else if (
+ m_dataType.getCategory() == Type::Category::Integer &&
+ dynamic_cast<IntegerType const&>(m_dataType).isSigned()
+ )
+ m_context << u256(m_dataType.getStorageBytes() - 1) << eth::Instruction::SIGNEXTEND;
else
m_context << ((u256(0x1) << (8 * m_dataType.getStorageBytes())) - 1) << eth::Instruction::AND;
}
@@ -148,6 +153,17 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc
m_context
<< (u256(0x1) << (256 - 8 * dynamic_cast<FixedBytesType const&>(m_dataType).getNumBytes()))
<< eth::Instruction::SWAP1 << eth::Instruction::DIV;
+ else if (
+ m_dataType.getCategory() == Type::Category::Integer &&
+ dynamic_cast<IntegerType const&>(m_dataType).isSigned()
+ )
+ // remove the higher order bits
+ m_context
+ << (u256(1) << (8 * (32 - m_dataType.getStorageBytes())))
+ << eth::Instruction::SWAP1
+ << eth::Instruction::DUP2
+ << eth::Instruction::MUL
+ << eth::Instruction::DIV;
m_context << eth::Instruction::MUL << eth::Instruction::OR;
// stack: value storage_ref updated_value
m_context << eth::Instruction::SWAP1 << eth::Instruction::SSTORE;