fix C compiler warning when checking int overflow for division by enum values on...
authorStefan Behnel <stefan_ml@behnel.de>
Fri, 6 Dec 2013 21:25:19 +0000 (22:25 +0100)
committerStefan Behnel <stefan_ml@behnel.de>
Fri, 6 Dec 2013 21:25:19 +0000 (22:25 +0100)
Cython/Compiler/ExprNodes.py

index 1c19b0b..78a227e 100644 (file)
@@ -9239,10 +9239,14 @@ class DivNode(NumBinopNode):
                 code.putln("}")
                 if self.type.is_int and self.type.signed and self.operator != '%':
                     code.globalstate.use_utility_code(division_overflow_test_code)
-                    code.putln("else if (sizeof(%s) == sizeof(long) && unlikely(%s == -1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(%s))) {" % (
-                                    self.type.declaration_code(''),
-                                    self.operand2.result(),
-                                    self.operand1.result()))
+                    type_of_op2 = self.operand2.type.declaration_code('')
+                    code.putln("else if (sizeof(%s) == sizeof(long)"
+                               " && (!(((%s)-1) > 0)) && unlikely(%s == (%s)-1)"
+                               " && unlikely(UNARY_NEG_WOULD_OVERFLOW(%s))) {" % (
+                               self.type.declaration_code(''),
+                               type_of_op2,
+                               self.operand2.result(), type_of_op2,
+                               self.operand1.result()))
                     code.put_ensure_gil()
                     code.putln('PyErr_Format(PyExc_OverflowError, "value too large to perform division");')
                     code.put_release_ensured_gil()