From b813038c3c506fb66632c290dee38ae0ab0ebcfe Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 5 Nov 2014 15:21:20 +0100 Subject: [PATCH] assert and exception corrections in solidity-external files. --- alethzero/MainWin.cpp | 4 ++++ libevmface/Instruction.h | 23 ++++++++++++++++++++--- liblll/Assembly.h | 10 +++++----- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 70f4b3017..dd417fbd3 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -1585,6 +1585,10 @@ void Main::on_data_textChanged() solidity::SourceReferenceFormatter::printExceptionInformation(error, exception, "Error", *scanner); solidity = "

Solidity

" + QString::fromStdString(error.str()).toHtmlEscaped() + "
"; } + catch (...) + { + solidity = "

Solidity

Uncaught exception.
"; + } } else { diff --git a/libevmface/Instruction.h b/libevmface/Instruction.h index 8392c410b..7cf205c03 100644 --- a/libevmface/Instruction.h +++ b/libevmface/Instruction.h @@ -32,6 +32,8 @@ namespace dev namespace eth { +class InvalidOpcode: public Exception {}; + /// Virtual machine bytecode instruction. enum class Instruction: uint8_t { @@ -177,13 +179,28 @@ enum class Instruction: uint8_t }; /// @returns the PUSH<_number> instruction -inline Instruction pushInstruction(unsigned _number) { assert(1 <= _number && _number <= 32); return Instruction(unsigned(Instruction::PUSH1) + _number - 1); } +inline Instruction pushInstruction(unsigned _number) +{ + if (asserts(1 <= _number && _number <= 32)) + BOOST_THROW_EXCEPTION(InvalidOpcode() << errinfo_comment("Invalid PUSH instruction requested.")); + return Instruction(unsigned(Instruction::PUSH1) + _number - 1); +} /// @returns the DUP<_number> instruction -inline Instruction dupInstruction(unsigned _number) { assert(1 <= _number && _number <= 16); return Instruction(unsigned(Instruction::DUP1) + _number - 1); } +inline Instruction dupInstruction(unsigned _number) +{ + if (asserts(1 <= _number && _number <= 16)) + BOOST_THROW_EXCEPTION(InvalidOpcode() << errinfo_comment("Invalid DUP instruction requested.")); + return Instruction(unsigned(Instruction::DUP1) + _number - 1); +} /// @returns the SWAP<_number> instruction -inline Instruction swapInstruction(unsigned _number) { assert(1 <= _number && _number <= 16); return Instruction(unsigned(Instruction::SWAP1) + _number - 1); } +inline Instruction swapInstruction(unsigned _number) +{ + if (asserts(1 <= _number && _number <= 16)) + BOOST_THROW_EXCEPTION(InvalidOpcode() << errinfo_comment("Invalid SWAP instruction requested.")); + return Instruction(unsigned(Instruction::SWAP1) + _number - 1); +} /// Information structure for a particular instruction. struct InstructionInfo diff --git a/liblll/Assembly.h b/liblll/Assembly.h index 38baee0c5..e39f1899b 100644 --- a/liblll/Assembly.h +++ b/liblll/Assembly.h @@ -45,8 +45,8 @@ public: AssemblyItem(Instruction _i): m_type(Operation), m_data((byte)_i) {} AssemblyItem(AssemblyItemType _type, u256 _data = 0): m_type(_type), m_data(_data) {} - AssemblyItem tag() const { assert(m_type == PushTag || m_type == Tag); return AssemblyItem(Tag, m_data); } - AssemblyItem pushTag() const { assert(m_type == PushTag || m_type == Tag); return AssemblyItem(PushTag, m_data); } + AssemblyItem tag() const { if (asserts(m_type == PushTag || m_type == Tag)) BOOST_THROW_EXCEPTION(Exception()); return AssemblyItem(Tag, m_data); } + AssemblyItem pushTag() const { if (asserts(m_type == PushTag || m_type == Tag)) BOOST_THROW_EXCEPTION(Exception()); return AssemblyItem(PushTag, m_data); } AssemblyItemType type() const { return m_type; } u256 data() const { return m_data; } @@ -94,7 +94,7 @@ public: AssemblyItem const& back() { return m_items.back(); } std::string backString() const { return m_items.size() && m_items.back().m_type == PushString ? m_strings.at((h256)m_items.back().m_data) : std::string(); } - void onePath() { assert(!m_totalDeposit && !m_baseDeposit); m_baseDeposit = m_deposit; m_totalDeposit = INT_MAX; } + void onePath() { if (asserts(!m_totalDeposit && !m_baseDeposit)) BOOST_THROW_EXCEPTION(InvalidDeposit()); m_baseDeposit = m_deposit; m_totalDeposit = INT_MAX; } void otherPath() { donePath(); m_totalDeposit = m_deposit; m_deposit = m_baseDeposit; } void donePaths() { donePath(); m_totalDeposit = m_baseDeposit = 0; } void ignored() { m_baseDeposit = m_deposit; } @@ -107,8 +107,8 @@ public: std::string out() const { std::stringstream ret; streamRLP(ret); return ret.str(); } int deposit() const { return m_deposit; } - void adjustDeposit(int _adjustment) { m_deposit += _adjustment; assert(m_deposit >= 0); } - void setDeposit(int _deposit) { m_deposit = _deposit; assert(m_deposit >= 0); } + void adjustDeposit(int _adjustment) { m_deposit += _adjustment; if (asserts(m_deposit >= 0)) BOOST_THROW_EXCEPTION(InvalidDeposit()); } + void setDeposit(int _deposit) { m_deposit = _deposit; if (asserts(m_deposit >= 0)) BOOST_THROW_EXCEPTION(InvalidDeposit()); } bytes assemble() const; Assembly& optimise(bool _enable);