diff options
author | Erik Kundt <bitshift@posteo.org> | 2018-10-11 01:33:45 +0800 |
---|---|---|
committer | Erik Kundt <bitshift@posteo.org> | 2018-10-11 01:49:25 +0800 |
commit | 763ae300233adb6650b6bc6d34c765f853960cd1 (patch) | |
tree | b6975fcec7c29707a4f4344c4c27ee4bc4f1e4c7 /libsolidity/analysis | |
parent | 06200b4b64c911ea2e0b12076e0fa02093dacbf8 (diff) | |
download | dexon-solidity-763ae300233adb6650b6bc6d34c765f853960cd1.tar.gz dexon-solidity-763ae300233adb6650b6bc6d34c765f853960cd1.tar.zst dexon-solidity-763ae300233adb6650b6bc6d34c765f853960cd1.zip |
Fixes crash on non-unsigned array index.
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 7 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.h | 2 |
2 files changed, 6 insertions, 3 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 39ea494d..1c406449 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -2299,7 +2299,8 @@ bool TypeChecker::visit(IndexAccess const& _access) m_errorReporter.typeError(_access.location(), "Index expression cannot be omitted."); else { - expectType(*index, IntegerType(256)); + if (!expectType(*index, IntegerType(256))) + m_errorReporter.fatalTypeError(_access.location(), "Index expression cannot be represented as an unsigned integer."); if (auto integerType = dynamic_cast<RationalNumberType const*>(type(*index).get())) if (bytesType.numBytes() <= integerType->literalValue(nullptr)) m_errorReporter.typeError(_access.location(), "Out of bounds array access."); @@ -2470,7 +2471,7 @@ Declaration const& TypeChecker::dereference(UserDefinedTypeName const& _typeName return *_typeName.annotation().referencedDeclaration; } -void TypeChecker::expectType(Expression const& _expression, Type const& _expectedType) +bool TypeChecker::expectType(Expression const& _expression, Type const& _expectedType) { _expression.accept(*this); if (!type(_expression)->isImplicitlyConvertibleTo(_expectedType)) @@ -2499,7 +2500,9 @@ void TypeChecker::expectType(Expression const& _expression, Type const& _expecte _expectedType.toString() + "." ); + return false; } + return true; } void TypeChecker::requireLValue(Expression const& _expression) diff --git a/libsolidity/analysis/TypeChecker.h b/libsolidity/analysis/TypeChecker.h index 8d25a88e..6ea99ca2 100644 --- a/libsolidity/analysis/TypeChecker.h +++ b/libsolidity/analysis/TypeChecker.h @@ -143,7 +143,7 @@ private: /// Runs type checks on @a _expression to infer its type and then checks that it is implicitly /// convertible to @a _expectedType. - void expectType(Expression const& _expression, Type const& _expectedType); + bool expectType(Expression const& _expression, Type const& _expectedType); /// Runs type checks on @a _expression to infer its type and then checks that it is an LValue. void requireLValue(Expression const& _expression); |