Change bytes to unsigned in FixedBytesType

This commit is contained in:
daniel 2018-04-30 22:58:04 -07:00 committed by Alex Beregszaszi
parent b34428249a
commit aa1542a9e1
3 changed files with 7 additions and 8 deletions

View File

@ -599,8 +599,7 @@ FixedPointType::FixedPointType(unsigned _totalBits, unsigned _fractionalDigits,
m_totalBits(_totalBits), m_fractionalDigits(_fractionalDigits), m_modifier(_modifier)
{
solAssert(
8 <= m_totalBits && m_totalBits <= 256 && m_totalBits % 8 == 0 &&
0 <= m_fractionalDigits && m_fractionalDigits <= 80,
8 <= m_totalBits && m_totalBits <= 256 && m_totalBits % 8 == 0 && m_fractionalDigits <= 80,
"Invalid bit number(s) for fixed type: " +
dev::toString(_totalBits) + "x" + dev::toString(_fractionalDigits)
);
@ -1264,7 +1263,7 @@ bool StringLiteralType::isValidUTF8() const
return dev::validateUTF8(m_value);
}
FixedBytesType::FixedBytesType(int _bytes): m_bytes(_bytes)
FixedBytesType::FixedBytesType(unsigned _bytes): m_bytes(_bytes)
{
solAssert(
m_bytes > 0 && m_bytes <= 32,

View File

@ -506,7 +506,7 @@ class FixedBytesType: public Type
public:
virtual Category category() const override { return Category::FixedBytes; }
explicit FixedBytesType(int _bytes);
explicit FixedBytesType(unsigned _bytes);
virtual bool isImplicitlyConvertibleTo(Type const& _convertTo) const override;
virtual bool isExplicitlyConvertibleTo(Type const& _convertTo) const override;
@ -524,10 +524,10 @@ public:
virtual TypePointer encodingType() const override { return shared_from_this(); }
virtual TypePointer interfaceType(bool) const override { return shared_from_this(); }
int numBytes() const { return m_bytes; }
unsigned numBytes() const { return m_bytes; }
private:
int m_bytes;
unsigned m_bytes;
};
/**

View File

@ -688,7 +688,7 @@ void CompilerUtils::convertType(
m_context << Instruction::POP << u256(0);
else if (targetType.numBytes() > typeOnStack.numBytes() || _cleanupNeeded)
{
int bytes = min(typeOnStack.numBytes(), targetType.numBytes());
unsigned bytes = min(typeOnStack.numBytes(), targetType.numBytes());
m_context << ((u256(1) << (256 - bytes * 8)) - 1);
m_context << Instruction::NOT << Instruction::AND;
}
@ -796,7 +796,7 @@ void CompilerUtils::convertType(
bytesConstRef data(value);
if (targetTypeCategory == Type::Category::FixedBytes)
{
int const numBytes = dynamic_cast<FixedBytesType const&>(_targetType).numBytes();
unsigned const numBytes = dynamic_cast<FixedBytesType const&>(_targetType).numBytes();
solAssert(data.size() <= 32, "");
m_context << (h256::Arith(h256(data, h256::AlignLeft)) & (~(u256(-1) >> (8 * numBytes))));
}