diff options
author | chriseth <c@ethdev.com> | 2016-08-12 22:50:37 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2016-08-17 17:27:15 +0800 |
commit | e7084d9e16d0b370cab29d1f9ba08f07844b55f5 (patch) | |
tree | 2458f2cce57410fd6a8e5eb38d5792a48a8b8b9c /libsolidity/codegen/ExpressionCompiler.cpp | |
parent | e4578982c6e1a39ca3457ab1844be37b500dedda (diff) | |
download | dexon-solidity-e7084d9e16d0b370cab29d1f9ba08f07844b55f5.tar.gz dexon-solidity-e7084d9e16d0b370cab29d1f9ba08f07844b55f5.tar.zst dexon-solidity-e7084d9e16d0b370cab29d1f9ba08f07844b55f5.zip |
Throw on division by zero.
Diffstat (limited to 'libsolidity/codegen/ExpressionCompiler.cpp')
-rw-r--r-- | libsolidity/codegen/ExpressionCompiler.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 1f93cf8c..4695ff96 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -1324,11 +1324,18 @@ void ExpressionCompiler::appendArithmeticOperatorCode(Token::Value _operator, Ty m_context << Instruction::MUL; break; case Token::Div: - m_context << (c_isSigned ? Instruction::SDIV : Instruction::DIV); - break; case Token::Mod: - m_context << (c_isSigned ? Instruction::SMOD : Instruction::MOD); + { + // Test for division by zero + m_context << Instruction::DUP2 << Instruction::ISZERO; + m_context.appendConditionalJumpTo(m_context.errorTag()); + + if (_operator == Token::Div) + m_context << (c_isSigned ? Instruction::SDIV : Instruction::DIV); + else + m_context << (c_isSigned ? Instruction::SMOD : Instruction::MOD); break; + } case Token::Exp: m_context << Instruction::EXP; break; |