mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #9095 from ethereum/conversionWarningsLibSolUtil
Adding fixes for signedness warnings in libsolutil
This commit is contained in:
commit
849b16babb
@ -74,8 +74,8 @@ string solidity::util::toHex(bytes const& _data, HexPrefix _prefix, HexCase _cas
|
||||
if (_case == HexCase::Mixed)
|
||||
chars = (rix-- & 2) == 0 ? lowerHexChars : upperHexChars;
|
||||
|
||||
ret[i++] = chars[(unsigned(c) / 16) & 0xf];
|
||||
ret[i++] = chars[unsigned(c) & 0xf];
|
||||
ret[i++] = chars[(static_cast<size_t>(c) >> 4ul) & 0xfu];
|
||||
ret[i++] = chars[c & 0xfu];
|
||||
}
|
||||
assertThrow(i == ret.size(), Exception, "");
|
||||
|
||||
|
@ -42,7 +42,7 @@
|
||||
template <class T, class U> std::vector<T>& operator+=(std::vector<T>& _a, U& _b)
|
||||
{
|
||||
for (auto const& i: _b)
|
||||
_a.push_back(i);
|
||||
_a.push_back(T(i));
|
||||
return _a;
|
||||
}
|
||||
/// Concatenate the contents of a container onto a vector, move variant.
|
||||
@ -379,7 +379,7 @@ void iterateReplacing(std::vector<T>& _vector, F const& _f)
|
||||
{
|
||||
if (!useModified)
|
||||
{
|
||||
std::move(_vector.begin(), _vector.begin() + i, back_inserter(modifiedVector));
|
||||
std::move(_vector.begin(), _vector.begin() + ptrdiff_t(i), back_inserter(modifiedVector));
|
||||
useModified = true;
|
||||
}
|
||||
modifiedVector += std::move(*r);
|
||||
@ -406,7 +406,7 @@ void iterateReplacingWindow(std::vector<T>& _vector, F const& _f, std::index_seq
|
||||
{
|
||||
if (!useModified)
|
||||
{
|
||||
std::move(_vector.begin(), _vector.begin() + i, back_inserter(modifiedVector));
|
||||
std::move(_vector.begin(), _vector.begin() + ptrdiff_t(i), back_inserter(modifiedVector));
|
||||
useModified = true;
|
||||
}
|
||||
modifiedVector += std::move(*r);
|
||||
|
@ -56,7 +56,7 @@ inline T readFile(std::string const& _file)
|
||||
return ret; // do not read empty file (MSVC does not like it)
|
||||
is.seekg(0, is.beg);
|
||||
|
||||
ret.resize((length + c_elementSize - 1) / c_elementSize);
|
||||
ret.resize((static_cast<size_t>(length) + c_elementSize - 1) / c_elementSize);
|
||||
is.read(const_cast<char*>(reinterpret_cast<char const*>(ret.data())), length);
|
||||
return ret;
|
||||
}
|
||||
@ -107,8 +107,8 @@ public:
|
||||
DisableConsoleBuffering()
|
||||
{
|
||||
tcgetattr(0, &m_termios);
|
||||
m_termios.c_lflag &= ~ICANON;
|
||||
m_termios.c_lflag &= ~ECHO;
|
||||
m_termios.c_lflag &= ~tcflag_t(ICANON);
|
||||
m_termios.c_lflag &= ~tcflag_t(ECHO);
|
||||
m_termios.c_cc[VMIN] = 1;
|
||||
m_termios.c_cc[VTIME] = 0;
|
||||
tcsetattr(0, TCSANOW, &m_termios);
|
||||
|
@ -62,7 +62,7 @@ string base58Encode(bytes const& _data)
|
||||
string output;
|
||||
while (data)
|
||||
{
|
||||
output += alphabet[size_t(data % alphabet.size())];
|
||||
output += alphabet[static_cast<size_t>(data % alphabet.size())];
|
||||
data /= alphabet.size();
|
||||
}
|
||||
reverse(output.begin(), output.end());
|
||||
|
@ -156,14 +156,14 @@ inline std::string formatNumberReadable(
|
||||
if (_useTruncation)
|
||||
{
|
||||
// return as interior-truncated hex.
|
||||
int len = str.size();
|
||||
size_t len = str.size();
|
||||
|
||||
if (len < 24)
|
||||
return str;
|
||||
|
||||
int const initialChars = (prefix == HexPrefix::Add) ? 6 : 4;
|
||||
int const finalChars = 4;
|
||||
int numSkipped = len - initialChars - finalChars;
|
||||
size_t const initialChars = (prefix == HexPrefix::Add) ? 6 : 4;
|
||||
size_t const finalChars = 4;
|
||||
size_t numSkipped = len - initialChars - finalChars;
|
||||
|
||||
return str.substr(0, initialChars) +
|
||||
"...{+" +
|
||||
|
@ -95,10 +95,10 @@ void hash256_block(RaIter1 message_digest, RaIter2 first, RaIter2 last) {
|
||||
word_t w[64];
|
||||
std::fill(w, w + 64, 0);
|
||||
for (std::size_t i = 0; i < 16; ++i) {
|
||||
w[i] = (static_cast<word_t>(mask_8bit(*(first + i * 4))) << 24) |
|
||||
(static_cast<word_t>(mask_8bit(*(first + i * 4 + 1))) << 16) |
|
||||
(static_cast<word_t>(mask_8bit(*(first + i * 4 + 2))) << 8) |
|
||||
(static_cast<word_t>(mask_8bit(*(first + i * 4 + 3))));
|
||||
w[i] = (static_cast<word_t>(mask_8bit(*(first + long(i) * 4))) << 24) |
|
||||
(static_cast<word_t>(mask_8bit(*(first + long(i) * 4 + 1))) << 16) |
|
||||
(static_cast<word_t>(mask_8bit(*(first + long(i) * 4 + 2))) << 8) |
|
||||
(static_cast<word_t>(mask_8bit(*(first + long(i) * 4 + 3))));
|
||||
}
|
||||
for (std::size_t i = 16; i < 64; ++i) {
|
||||
w[i] = mask_32bit(ssig1(w[i - 2]) + w[i - 7] + ssig0(w[i - 15]) +
|
||||
@ -196,10 +196,10 @@ class hash256_one_by_one {
|
||||
std::copy(first, last, std::back_inserter(buffer_));
|
||||
std::size_t i = 0;
|
||||
for (; i + 64 <= buffer_.size(); i += 64) {
|
||||
detail::hash256_block(h_, buffer_.begin() + i,
|
||||
buffer_.begin() + i + 64);
|
||||
detail::hash256_block(h_, buffer_.begin() + long(i),
|
||||
buffer_.begin() + long(i) + 64);
|
||||
}
|
||||
buffer_.erase(buffer_.begin(), buffer_.begin() + i);
|
||||
buffer_.erase(buffer_.begin(), buffer_.begin() + long(i));
|
||||
}
|
||||
|
||||
void finish() {
|
||||
@ -297,20 +297,20 @@ void hash256_impl(RaIter first, RaIter last, OutIter first2, OutIter last2, int,
|
||||
|
||||
template <typename InputIter, typename OutIter>
|
||||
void hash256_impl(InputIter first, InputIter last, OutIter first2,
|
||||
OutIter last2, int buffer_size, std::input_iterator_tag) {
|
||||
OutIter last2, size_t buffer_size, std::input_iterator_tag) {
|
||||
std::vector<byte_t> buffer(buffer_size);
|
||||
hash256_one_by_one hasher;
|
||||
// hasher.init();
|
||||
while (first != last) {
|
||||
int size = buffer_size;
|
||||
for (int i = 0; i != buffer_size; ++i, ++first) {
|
||||
size_t size = buffer_size;
|
||||
for (size_t i = 0; i != buffer_size; ++i, ++first) {
|
||||
if (first == last) {
|
||||
size = i;
|
||||
break;
|
||||
}
|
||||
buffer[i] = *first;
|
||||
}
|
||||
hasher.process(buffer.begin(), buffer.begin() + size);
|
||||
hasher.process(buffer.begin(), buffer.begin() + ptrdiff_t(size));
|
||||
}
|
||||
hasher.finish();
|
||||
hasher.get_hash_bytes(first2, last2);
|
||||
|
@ -36,10 +36,10 @@ BOOST_AUTO_TEST_CASE(test_small)
|
||||
BOOST_CHECK_EQUAL(ipfsHashBase58({}), "QmbFMke1KXqnYyBBWxB74N4c5SBnJMVAiMNRcGu6x1AwQH");
|
||||
BOOST_CHECK_EQUAL(ipfsHashBase58("x"), "QmULKig5Fxrs2sC4qt9nNduucXfb92AFYQ6Hi3YRqDmrYC");
|
||||
BOOST_CHECK_EQUAL(ipfsHashBase58("Solidity\n"), "QmSsm9M7PQRBnyiz1smizk8hZw3URfk8fSeHzeTo3oZidS");
|
||||
BOOST_CHECK_EQUAL(ipfsHashBase58(string(size_t(200), char(0))), "QmSXR1N23uWzsANi8wpxMPw5dmmhqBVUAb4hUrHVLpNaMr");
|
||||
BOOST_CHECK_EQUAL(ipfsHashBase58(string(size_t(10250), char(0))), "QmVJJBB3gKKBWYC9QTywpH8ZL1bDeTDJ17B63Af5kino9i");
|
||||
BOOST_CHECK_EQUAL(ipfsHashBase58(string(size_t(100000), char(0))), "QmYgKa25YqEGpQmmZtPPFMNK3kpqqneHk6nMSEUYryEX1C");
|
||||
BOOST_CHECK_EQUAL(ipfsHashBase58(string(size_t(121071), char(0))), "QmdMdRshQmqvyc92N82r7AKYdUF5FRh4DJo6GtrmEk3wgj");
|
||||
BOOST_CHECK_EQUAL(ipfsHashBase58(string(200ul, char(0))), "QmSXR1N23uWzsANi8wpxMPw5dmmhqBVUAb4hUrHVLpNaMr");
|
||||
BOOST_CHECK_EQUAL(ipfsHashBase58(string(10250ul, char(0))), "QmVJJBB3gKKBWYC9QTywpH8ZL1bDeTDJ17B63Af5kino9i");
|
||||
BOOST_CHECK_EQUAL(ipfsHashBase58(string(100000ul, char(0))), "QmYgKa25YqEGpQmmZtPPFMNK3kpqqneHk6nMSEUYryEX1C");
|
||||
BOOST_CHECK_EQUAL(ipfsHashBase58(string(121071ul, char(0))), "QmdMdRshQmqvyc92N82r7AKYdUF5FRh4DJo6GtrmEk3wgj");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_medium)
|
||||
|
Loading…
Reference in New Issue
Block a user