mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #9138 from ethereum/conversionWarningFixes2
Fixing conversion errors after adding `-Wconversion` flag
This commit is contained in:
commit
f3150a2b34
@ -59,7 +59,7 @@ void AssemblyItem::setPushTagSubIdAndTag(size_t _subId, size_t _tag)
|
||||
setData(data);
|
||||
}
|
||||
|
||||
unsigned AssemblyItem::bytesRequired(unsigned _addressLength) const
|
||||
size_t AssemblyItem::bytesRequired(size_t _addressLength) const
|
||||
{
|
||||
switch (m_type)
|
||||
{
|
||||
@ -69,7 +69,7 @@ unsigned AssemblyItem::bytesRequired(unsigned _addressLength) const
|
||||
case PushString:
|
||||
return 1 + 32;
|
||||
case Push:
|
||||
return 1 + max<unsigned>(1, util::bytesRequired(data()));
|
||||
return 1 + max<size_t>(1, util::bytesRequired(data()));
|
||||
case PushSubSize:
|
||||
case PushProgramSize:
|
||||
return 1 + 4; // worst case: a 16MB program
|
||||
|
@ -133,7 +133,7 @@ public:
|
||||
|
||||
/// @returns an upper bound for the number of bytes required by this item, assuming that
|
||||
/// the value of a jump tag takes @a _addressLength bytes.
|
||||
unsigned bytesRequired(unsigned _addressLength) const;
|
||||
size_t bytesRequired(size_t _addressLength) const;
|
||||
size_t arguments() const;
|
||||
size_t returnValues() const;
|
||||
size_t deposit() const { return returnValues() - arguments(); }
|
||||
|
@ -107,7 +107,7 @@ tuple<int, int> CharStream::translatePositionToLineColumn(int _position) const
|
||||
using size_type = string::size_type;
|
||||
using diff_type = string::difference_type;
|
||||
size_type searchPosition = min<size_type>(m_source.size(), size_type(_position));
|
||||
int lineNumber = count(m_source.begin(), m_source.begin() + diff_type(searchPosition), '\n');
|
||||
int lineNumber = static_cast<int>(count(m_source.begin(), m_source.begin() + diff_type(searchPosition), '\n'));
|
||||
size_type lineStart;
|
||||
if (searchPosition == 0)
|
||||
lineStart = 0;
|
||||
|
@ -179,7 +179,7 @@ bool Scanner::scanHexByte(char& o_scannedByte)
|
||||
rollback(i);
|
||||
return false;
|
||||
}
|
||||
x = x * 16 + d;
|
||||
x = static_cast<char>(x * 16 + d);
|
||||
advance();
|
||||
}
|
||||
o_scannedByte = x;
|
||||
@ -197,7 +197,7 @@ std::optional<unsigned> Scanner::scanUnicode()
|
||||
rollback(i);
|
||||
return {};
|
||||
}
|
||||
x = x * 16 + static_cast<size_t>(d);
|
||||
x = x * 16 + static_cast<unsigned>(d);
|
||||
advance();
|
||||
}
|
||||
return x;
|
||||
|
@ -106,7 +106,7 @@ bytes solidity::util::fromHex(std::string const& _s, WhenError _throw)
|
||||
{
|
||||
int h = fromHex(_s[s++], _throw);
|
||||
if (h != -1)
|
||||
ret.push_back(h);
|
||||
ret.push_back(static_cast<uint8_t>(h));
|
||||
else
|
||||
return bytes();
|
||||
}
|
||||
@ -115,7 +115,7 @@ bytes solidity::util::fromHex(std::string const& _s, WhenError _throw)
|
||||
int h = fromHex(_s[i], _throw);
|
||||
int l = fromHex(_s[i + 1], _throw);
|
||||
if (h != -1 && l != -1)
|
||||
ret.push_back((uint8_t)(h * 16 + l));
|
||||
ret.push_back(static_cast<uint8_t>(h * 16 + l));
|
||||
else
|
||||
return bytes();
|
||||
}
|
||||
@ -148,14 +148,14 @@ string solidity::util::getChecksummedAddress(string const& _addr)
|
||||
h256 hash = keccak256(boost::algorithm::to_lower_copy(s, std::locale::classic()));
|
||||
|
||||
string ret = "0x";
|
||||
for (size_t i = 0; i < 40; ++i)
|
||||
for (unsigned i = 0; i < 40; ++i)
|
||||
{
|
||||
char addressCharacter = s[i];
|
||||
unsigned nibble = (unsigned(hash[i / 2]) >> (4 * (1 - (i % 2)))) & 0xf;
|
||||
uint8_t nibble = hash[i / 2u] >> (4u * (1u - (i % 2u))) & 0xf;
|
||||
if (nibble >= 8)
|
||||
ret += toupper(addressCharacter);
|
||||
ret += static_cast<char>(toupper(addressCharacter));
|
||||
else
|
||||
ret += tolower(addressCharacter);
|
||||
ret += static_cast<char>(tolower(addressCharacter));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -64,10 +64,44 @@ public:
|
||||
FixedHash(Arith const& _arith) { toBigEndian(_arith, m_data); }
|
||||
|
||||
/// Explicitly construct, copying from a byte array.
|
||||
explicit FixedHash(bytes const& _b, ConstructFromHashType _t = FailIfDifferent) { if (_b.size() == N) memcpy(m_data.data(), _b.data(), std::min<unsigned>(_b.size(), N)); else { m_data.fill(0); if (_t != FailIfDifferent) { auto c = std::min<unsigned>(_b.size(), N); for (unsigned i = 0; i < c; ++i) m_data[_t == AlignRight ? N - 1 - i : i] = _b[_t == AlignRight ? _b.size() - 1 - i : i]; } } }
|
||||
explicit FixedHash(bytes const& _array, ConstructFromHashType _sizeMismatchBehavior = FailIfDifferent)
|
||||
{
|
||||
if (_array.size() == N)
|
||||
memcpy(m_data.data(), _array.data(), _array.size());
|
||||
else
|
||||
{
|
||||
m_data.fill(0);
|
||||
if (_sizeMismatchBehavior != FailIfDifferent)
|
||||
{
|
||||
auto bytesToCopy = std::min<size_t>(_array.size(), N);
|
||||
for (size_t i = 0; i < bytesToCopy; ++i)
|
||||
if (_sizeMismatchBehavior == AlignRight)
|
||||
m_data[N - 1 - i] = _array[_array.size() - 1 - i];
|
||||
else
|
||||
m_data[i] = _array[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Explicitly construct, copying from a byte array.
|
||||
explicit FixedHash(bytesConstRef _b, ConstructFromHashType _t = FailIfDifferent) { if (_b.size() == N) memcpy(m_data.data(), _b.data(), std::min<unsigned>(_b.size(), N)); else { m_data.fill(0); if (_t != FailIfDifferent) { auto c = std::min<unsigned>(_b.size(), N); for (unsigned i = 0; i < c; ++i) m_data[_t == AlignRight ? N - 1 - i : i] = _b[_t == AlignRight ? _b.size() - 1 - i : i]; } } }
|
||||
explicit FixedHash(bytesConstRef _b, ConstructFromHashType _t = FailIfDifferent)
|
||||
{
|
||||
if (_b.size() == N)
|
||||
memcpy(m_data.data(), _b.data(), std::min<size_t>(_b.size(), N));
|
||||
else
|
||||
{
|
||||
m_data.fill(0);
|
||||
if (_t != FailIfDifferent)
|
||||
{
|
||||
auto c = std::min<size_t>(_b.size(), N);
|
||||
for (size_t i = 0; i < c; ++i)
|
||||
if (_t == AlignRight)
|
||||
m_data[N - 1 - i] = _b[_b.size() - 1 - i];
|
||||
else
|
||||
m_data[i] = _b[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Explicitly construct, copying from a string.
|
||||
explicit FixedHash(std::string const& _s, ConstructFromStringType _t = FromHex, ConstructFromHashType _ht = FailIfDifferent): FixedHash(_t == FromHex ? fromHex(_s, WhenError::Throw) : solidity::util::asBytes(_s), _ht) {}
|
||||
|
@ -69,25 +69,25 @@ static uint64_t const RC[24] = \
|
||||
#define REPEAT6(e) e e e e e e
|
||||
#define REPEAT24(e) REPEAT6(e e e e)
|
||||
#define REPEAT5(e) e e e e e
|
||||
#define FOR5(v, s, e) \
|
||||
#define FOR5(type, v, s, e) \
|
||||
v = 0; \
|
||||
REPEAT5(e; v += s;)
|
||||
REPEAT5(e; v = static_cast<type>(v + s);)
|
||||
|
||||
/*** Keccak-f[1600] ***/
|
||||
static inline void keccakf(void* state) {
|
||||
uint64_t* a = (uint64_t*)state;
|
||||
auto* a = static_cast<uint64_t*>(state);
|
||||
uint64_t b[5] = {0};
|
||||
|
||||
for (int i = 0; i < 24; i++)
|
||||
{
|
||||
uint8_t x, y;
|
||||
// Theta
|
||||
FOR5(x, 1,
|
||||
FOR5(uint8_t, x, 1,
|
||||
b[x] = 0;
|
||||
FOR5(y, 5,
|
||||
FOR5(uint8_t, y, 5,
|
||||
b[x] ^= a[x + y]; ))
|
||||
FOR5(x, 1,
|
||||
FOR5(y, 5,
|
||||
FOR5(uint8_t, x, 1,
|
||||
FOR5(uint8_t, y, 5,
|
||||
a[y + x] ^= b[(x + 4) % 5] ^ rol(b[(x + 1) % 5], 1); ))
|
||||
// Rho and pi
|
||||
uint64_t t = a[1];
|
||||
@ -97,11 +97,12 @@ static inline void keccakf(void* state) {
|
||||
t = b[0];
|
||||
x++; )
|
||||
// Chi
|
||||
FOR5(y,
|
||||
FOR5(uint8_t,
|
||||
y,
|
||||
5,
|
||||
FOR5(x, 1,
|
||||
FOR5(uint8_t, x, 1,
|
||||
b[x] = a[y + x];)
|
||||
FOR5(x, 1,
|
||||
FOR5(uint8_t, x, 1,
|
||||
a[y + x] = b[x] ^ ((~b[(x + 1) % 5]) & b[(x + 2) % 5]); ))
|
||||
// Iota
|
||||
a[0] ^= RC[i];
|
||||
|
Loading…
Reference in New Issue
Block a user