aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-04-12 06:39:20 +0800
committerchriseth <chris@ethereum.org>2018-04-16 18:47:38 +0800
commit4c1d39b7a2bc9e58436da0bf85edf5cd74d5a882 (patch)
tree7c75fe2be27af64c309e8dc8bcda00a74adbc361 /libsolidity
parentd8030c9b2ad0965d7de2637982005da9f4b6b93a (diff)
downloaddexon-solidity-4c1d39b7a2bc9e58436da0bf85edf5cd74d5a882.tar
dexon-solidity-4c1d39b7a2bc9e58436da0bf85edf5cd74d5a882.tar.gz
dexon-solidity-4c1d39b7a2bc9e58436da0bf85edf5cd74d5a882.tar.bz2
dexon-solidity-4c1d39b7a2bc9e58436da0bf85edf5cd74d5a882.tar.lz
dexon-solidity-4c1d39b7a2bc9e58436da0bf85edf5cd74d5a882.tar.xz
dexon-solidity-4c1d39b7a2bc9e58436da0bf85edf5cd74d5a882.tar.zst
dexon-solidity-4c1d39b7a2bc9e58436da0bf85edf5cd74d5a882.zip
Properly force-clean for shortening bytesXX conversions.
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/codegen/CompilerUtils.cpp19
1 files changed, 9 insertions, 10 deletions
diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp
index b4550153..4af7d905 100644
--- a/libsolidity/codegen/CompilerUtils.cpp
+++ b/libsolidity/codegen/CompilerUtils.cpp
@@ -684,19 +684,17 @@ void CompilerUtils::convertType(
// clear for conversion to longer bytes
solAssert(targetTypeCategory == Type::Category::FixedBytes, "Invalid type conversion requested.");
FixedBytesType const& targetType = dynamic_cast<FixedBytesType const&>(_targetType);
- if (targetType.numBytes() > typeOnStack.numBytes() || _cleanupNeeded)
+ if (typeOnStack.numBytes() == 0 || targetType.numBytes() == 0)
+ m_context << Instruction::POP << u256(0);
+ else if (targetType.numBytes() > typeOnStack.numBytes() || _cleanupNeeded)
{
- if (typeOnStack.numBytes() == 0)
- m_context << Instruction::POP << u256(0);
- else
- {
- m_context << ((u256(1) << (256 - typeOnStack.numBytes() * 8)) - 1);
- m_context << Instruction::NOT << Instruction::AND;
- }
+ int bytes = min(typeOnStack.numBytes(), targetType.numBytes());
+ m_context << ((u256(1) << (256 - bytes * 8)) - 1);
+ m_context << Instruction::NOT << Instruction::AND;
}
}
- }
break;
+ }
case Type::Category::Enum:
solAssert(_targetType == _typeOnStack || targetTypeCategory == Type::Category::Integer, "");
if (enumOverflowCheckPending)
@@ -798,8 +796,9 @@ void CompilerUtils::convertType(
bytesConstRef data(value);
if (targetTypeCategory == Type::Category::FixedBytes)
{
+ int const numBytes = dynamic_cast<FixedBytesType const&>(_targetType).numBytes();
solAssert(data.size() <= 32, "");
- m_context << h256::Arith(h256(data, h256::AlignLeft));
+ m_context << (h256::Arith(h256(data, h256::AlignLeft)) & (~(u256(-1) >> (8 * numBytes))));
}
else if (targetTypeCategory == Type::Category::Array)
{