Commit be19c1f3 authored by Jim Fulton's avatar Jim Fulton

Fixed: integer overflow on 32-bit machines wasn't detected correctly

  under Python 3.
parent 4c6f43b6
...@@ -19,9 +19,10 @@ ...@@ -19,9 +19,10 @@
#define KEY_CHECK INT_CHECK #define KEY_CHECK INT_CHECK
#define COPY_KEY_TO_OBJECT(O, K) O=INT_FROM_LONG(K) #define COPY_KEY_TO_OBJECT(O, K) O=INT_FROM_LONG(K)
#define COPY_KEY_FROM_ARG(TARGET, ARG, STATUS) \ #define COPY_KEY_FROM_ARG(TARGET, ARG, STATUS) \
if (INT_CHECK(ARG)) { \ if (INT_CHECK(ARG)) { \
long vcopy = INT_AS_LONG(ARG); \ long vcopy = INT_AS_LONG(ARG); \
if ((int)vcopy != vcopy) { \ if (PyErr_Occurred()) { (STATUS)=0; (TARGET)=0; } \
else if ((int)vcopy != vcopy) { \
PyErr_SetString(PyExc_TypeError, "integer out of range"); \ PyErr_SetString(PyExc_TypeError, "integer out of range"); \
(STATUS)=0; (TARGET)=0; \ (STATUS)=0; (TARGET)=0; \
} \ } \
......
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
#define COPY_VALUE_FROM_ARG(TARGET, ARG, STATUS) \ #define COPY_VALUE_FROM_ARG(TARGET, ARG, STATUS) \
if (INT_CHECK(ARG)) { \ if (INT_CHECK(ARG)) { \
long vcopy = INT_AS_LONG(ARG); \ long vcopy = INT_AS_LONG(ARG); \
if ((int)vcopy != vcopy) { \ if (PyErr_Occurred()) { (STATUS)=0; (TARGET)=0; } \
else if ((int)vcopy != vcopy) { \
PyErr_SetString(PyExc_TypeError, "integer out of range"); \ PyErr_SetString(PyExc_TypeError, "integer out of range"); \
(STATUS)=0; (TARGET)=0; \ (STATUS)=0; (TARGET)=0; \
} \ } \
......
...@@ -11,8 +11,11 @@ ...@@ -11,8 +11,11 @@
# FOR A PARTICULAR PURPOSE # FOR A PARTICULAR PURPOSE
# #
############################################################################## ##############################################################################
import sys
import unittest import unittest
python3 = sys.version_info >= (3, )
from BTrees.tests.common import permutations from BTrees.tests.common import permutations
...@@ -451,8 +454,12 @@ class FamilyTest(unittest.TestCase): ...@@ -451,8 +454,12 @@ class FamilyTest(unittest.TestCase):
# the characteristics change to match the 64 bit version, please # the characteristics change to match the 64 bit version, please
# feel free to change. # feel free to change.
big = BTrees.family32.maxint + 1 big = BTrees.family32.maxint + 1
self.assertRaises(TypeError, s.insert, big) if python3:
self.assertRaises(TypeError, s.insert, BTrees.family32.minint - 1) expected_exception = OverflowError
else:
expected_exception = TypeError
self.assertRaises(expected_exception, s.insert,
BTrees.family32.minint - 1)
self.check_pickling(BTrees.family32) self.check_pickling(BTrees.family32)
def test64(self): def test64(self):
......
...@@ -113,6 +113,8 @@ class _IIBTreeTestBase(BTreeTests): ...@@ -113,6 +113,8 @@ class _IIBTreeTestBase(BTreeTests):
i = int(i) i = int(i)
try: try:
b[i] = 0 b[i] = 0
except OverflowError:
self.assertRaises(OverflowError, b.__setitem__, 0, i)
except TypeError: except TypeError:
self.assertRaises(TypeError, b.__setitem__, 0, i) self.assertRaises(TypeError, b.__setitem__, 0, i)
else: else:
......
``BTrees`` Changelog ``BTrees`` Changelog
==================== ====================
- Fixed: integer overflow on 32-bit machines wasn't detected correctly
under Python 3.
4.0.9 (unreleased) 4.0.9 (unreleased)
------------------ ------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment