diff --git a/libdevcore/TrieCommon.cpp b/libdevcore/TrieCommon.cpp index ff44906b1..5bf6070ee 100644 --- a/libdevcore/TrieCommon.cpp +++ b/libdevcore/TrieCommon.cpp @@ -60,7 +60,7 @@ std::string hexPrefixEncode(bytes const& _hexVector, bool _leaf, int _begin, int std::string hexPrefixEncode(bytesConstRef _data, bool _leaf, int _beginNibble, int _endNibble, unsigned _offset) { unsigned begin = _beginNibble + _offset; - unsigned end = (_endNibble < 0 ? (_data.size() * 2 - _offset) + 1 + _endNibble : _endNibble) + _offset; + unsigned end = (_endNibble < 0 ? ((int)(_data.size() * 2 - _offset) + 1) + _endNibble : _endNibble) + _offset; bool odd = (end - begin) & 1; std::string ret(1, ((_leaf ? 2 : 0) | (odd ? 1 : 0)) * 16); diff --git a/libethereum/EthereumHost.cpp b/libethereum/EthereumHost.cpp index 4a13a247f..9980f4339 100644 --- a/libethereum/EthereumHost.cpp +++ b/libethereum/EthereumHost.cpp @@ -178,8 +178,9 @@ tuple>, vector>, vector return true; }); - chosen.reserve((peerCount * _percent + 99) / 100); - for (unsigned i = (peerCount * _percent + 99) / 100; i-- && allowed.size();) + size_t chosenSize = (peerCount * _percent + 99) / 100; + chosen.reserve(chosenSize); + for (unsigned i = chosenSize; i && allowed.size(); i--) { unsigned n = rand() % allowed.size(); chosen.push_back(std::move(allowed[n])); diff --git a/libsolidity/CompilerUtils.cpp b/libsolidity/CompilerUtils.cpp index 5bd6de13b..e763a3941 100644 --- a/libsolidity/CompilerUtils.cpp +++ b/libsolidity/CompilerUtils.cpp @@ -91,13 +91,11 @@ void CompilerUtils::loadFromMemoryDynamic( } } -unsigned CompilerUtils::storeInMemory(unsigned _offset, Type const& _type, bool _padToWordBoundaries) +void CompilerUtils::storeInMemory(unsigned _offset) { - solAssert(_type.getCategory() != Type::Category::Array, "Unable to statically store dynamic type."); - unsigned numBytes = prepareMemoryStore(_type, _padToWordBoundaries); + unsigned numBytes = prepareMemoryStore(IntegerType(256), true); if (numBytes > 0) m_context << u256(_offset) << eth::Instruction::MSTORE; - return numBytes; } void CompilerUtils::storeInMemoryDynamic(Type const& _type, bool _padToWordBoundaries) @@ -599,11 +597,10 @@ unsigned CompilerUtils::getSizeOnStack(vector> const& _va return size; } -void CompilerUtils::computeHashStatic(Type const& _type, bool _padToWordBoundaries) +void CompilerUtils::computeHashStatic() { - unsigned length = storeInMemory(0, _type, _padToWordBoundaries); - solAssert(length <= CompilerUtils::freeMemoryPointer, ""); - m_context << u256(length) << u256(0) << eth::Instruction::SHA3; + storeInMemory(0); + m_context << u256(32) << u256(0) << eth::Instruction::SHA3; } unsigned CompilerUtils::loadFromMemoryHelper(Type const& _type, bool _fromCalldata, bool _padToWordBoundaries) diff --git a/libsolidity/CompilerUtils.h b/libsolidity/CompilerUtils.h index a880f9ee4..9a599f7fa 100644 --- a/libsolidity/CompilerUtils.h +++ b/libsolidity/CompilerUtils.h @@ -65,16 +65,10 @@ public: bool _padToWordBoundaries = true, bool _keepUpdatedMemoryOffset = true ); - /// Stores data from stack in memory. + /// Stores a 256 bit integer from stack in memory. /// @param _offset offset in memory /// @param _type type of the data on the stack - /// @param _padToWordBoundaries if true, pad the data to word (32 byte) boundaries - /// @returns the number of bytes written to memory (can be different from _bytes if - /// _padToWordBoundaries is true) - unsigned storeInMemory(unsigned _offset, - Type const& _type = IntegerType(256), - bool _padToWordBoundaries = false - ); + void storeInMemory(unsigned _offset); /// Dynamic version of @see storeInMemory, expects the memory offset below the value on the stack /// and also updates that. For arrays, only copies the data part. /// Stack pre: memory_offset value... @@ -124,10 +118,8 @@ public: static unsigned getSizeOnStack(std::vector const& _variables); static unsigned getSizeOnStack(std::vector> const& _variableTypes); - /// Appends code that computes tha SHA3 hash of the topmost stack element of type @a _type. - /// If @a _pad is set, padds the type to muliples of 32 bytes. - /// @note Only works for types of fixed size. - void computeHashStatic(Type const& _type = IntegerType(256), bool _padToWordBoundaries = false); + /// Appends code that computes tha SHA3 hash of the topmost stack element of 32 byte type. + void computeHashStatic(); /// Bytes we need to the start of call data. /// - The size in bytes of the function (hash) identifier.