aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2016-08-17 22:43:13 +0800
committerGitHub <noreply@github.com>2016-08-17 22:43:13 +0800
commitd6579a0a5f99425eae95329b77e07ea072122924 (patch)
tree210f3cf17b58c674060d834c6ae2dfe3ec3cd17a /libsolidity
parent6baa982a6a95189af8199e719e62314b1073aa62 (diff)
parent34f9a59f18dcf8601d910aef599b2589dc080e2d (diff)
downloaddexon-solidity-d6579a0a5f99425eae95329b77e07ea072122924.tar
dexon-solidity-d6579a0a5f99425eae95329b77e07ea072122924.tar.gz
dexon-solidity-d6579a0a5f99425eae95329b77e07ea072122924.tar.bz2
dexon-solidity-d6579a0a5f99425eae95329b77e07ea072122924.tar.lz
dexon-solidity-d6579a0a5f99425eae95329b77e07ea072122924.tar.xz
dexon-solidity-d6579a0a5f99425eae95329b77e07ea072122924.tar.zst
dexon-solidity-d6579a0a5f99425eae95329b77e07ea072122924.zip
Merge pull request #888 from chriseth/throwOnDivZero
Throw on division by zero.
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/codegen/ExpressionCompiler.cpp13
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;