Skip to content

Commit 24b9235

Browse files
committed
Add missing checks for div by zero
1 parent 3a55a39 commit 24b9235

File tree

2 files changed

+7
-0
lines changed
  • graalpython

2 files changed

+7
-0
lines changed

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_types.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@
4444
*graalpython.lib-python.3.test.test_types.TypesTests.test_strings
4545
*graalpython.lib-python.3.test.test_types.TypesTests.test_truth_values
4646
*graalpython.lib-python.3.test.test_types.TypesTests.test_type_function
47+
*graalpython.lib-python.3.test.test_types.TypesTests.test_zero_division

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats/FloatBuiltins.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,26 +855,31 @@ public static double op(double left, double right) {
855855
abstract static class DivNode extends FloatBinaryBuiltinNode {
856856
@Specialization
857857
double doDD(double left, double right) {
858+
raiseDivisionByZero(right == 0.0);
858859
return left / right;
859860
}
860861

861862
@Specialization
862863
double doDL(double left, long right) {
864+
raiseDivisionByZero(right == 0);
863865
return left / right;
864866
}
865867

866868
@Specialization
867869
double doDPi(double left, PInt right) {
870+
raiseDivisionByZero(right.isZero());
868871
return left / right.doubleValueWithOverflow(getRaiseNode());
869872
}
870873

871874
@Specialization
872875
double div(long left, double right) {
876+
raiseDivisionByZero(right == 0.0);
873877
return left / right;
874878
}
875879

876880
@Specialization
877881
double div(PInt left, double right) {
882+
raiseDivisionByZero(right == 0.0);
878883
return left.doubleValueWithOverflow(getRaiseNode()) / right;
879884
}
880885

@@ -883,6 +888,7 @@ Object doDP(VirtualFrame frame, long left, PythonNativeObject right,
883888
@Cached FromNativeSubclassNode getFloat) {
884889
Double rPrimitive = getFloat.execute(frame, right);
885890
if (rPrimitive != null) {
891+
raiseDivisionByZero(rPrimitive == 0.0);
886892
return left / rPrimitive;
887893
} else {
888894
return PNotImplemented.NOT_IMPLEMENTED;

0 commit comments

Comments
 (0)