mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fixing conversion warnings in CommonData.cpp
Co-authored-by: Kamil Śliwak <kamil.sliwak@codepoets.it>
This commit is contained in:
parent
d7f29a33b9
commit
c8759b8031
@ -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) {}
|
||||
|
Loading…
Reference in New Issue
Block a user