Commit ae1636e9 authored by Jim Fulton's avatar Jim Fulton

Fixed bug:

- BTree sets and tree sets didn't correctly check values passed to
  update or to constructors, causing Python to exit under certain
  circumstances.
parent 9f39b619
...@@ -32,10 +32,9 @@ Set_insert(Bucket *self, PyObject *args) ...@@ -32,10 +32,9 @@ Set_insert(Bucket *self, PyObject *args)
static int static int
_Set_update(Bucket *self, PyObject *seq) _Set_update(Bucket *self, PyObject *seq)
{ {
int n = -1; int n=0, ind=0;
PyObject *iter, *v; PyObject *iter, *v;
int ind;
iter = PyObject_GetIter(seq); iter = PyObject_GetIter(seq);
if (iter == NULL) if (iter == NULL)
return -1; return -1;
...@@ -55,15 +54,11 @@ _Set_update(Bucket *self, PyObject *seq) ...@@ -55,15 +54,11 @@ _Set_update(Bucket *self, PyObject *seq)
else else
n += ind; n += ind;
} }
/* n starts out at -1, which is the error return value. If
this point is reached, then there is no error. n must be
incremented to account for the initial value of -1 instead of
0.
*/
n++;
err: err:
Py_DECREF(iter); Py_DECREF(iter);
if (ind < 0)
return -1;
return n; return n;
} }
......
...@@ -35,9 +35,8 @@ TreeSet_insert(BTree *self, PyObject *args) ...@@ -35,9 +35,8 @@ TreeSet_insert(BTree *self, PyObject *args)
static int static int
_TreeSet_update(BTree *self, PyObject *seq) _TreeSet_update(BTree *self, PyObject *seq)
{ {
int n = -1; int n=0, ind=0;
PyObject *iter, *v; PyObject *iter, *v;
int ind;
iter = PyObject_GetIter(seq); iter = PyObject_GetIter(seq);
if (iter == NULL) if (iter == NULL)
...@@ -58,15 +57,11 @@ _TreeSet_update(BTree *self, PyObject *seq) ...@@ -58,15 +57,11 @@ _TreeSet_update(BTree *self, PyObject *seq)
else else
n += ind; n += ind;
} }
/* n starts out at -1, which is the error return value. If
this point is reached, then there is no error. n must be
incremented to account for the initial value of -1 instead of
0.
*/
n++;
err: err:
Py_DECREF(iter); Py_DECREF(iter);
if (ind < 0)
return -1;
return n; return n;
} }
......
...@@ -1387,9 +1387,12 @@ class TestIFBTrees(TestCase): ...@@ -1387,9 +1387,12 @@ class TestIFBTrees(TestCase):
def _noneraisesvalue(self): def _noneraisesvalue(self):
self.t[1] = None self.t[1] = None
class TestIOSets(TestCase): class TestI_Sets(TestCase):
def setUp(self):
self.t = IOSet() def testBadBadKeyAfterFirst(self):
self.assertRaises(TypeError, self.t.__class__, [1, ''])
self.assertRaises(TypeError, self.t.update, [1, ''])
del self.t
def testNonIntegerInsertRaises(self): def testNonIntegerInsertRaises(self):
self.assertRaises(TypeError,self._insertstringraises) self.assertRaises(TypeError,self._insertstringraises)
...@@ -1405,6 +1408,47 @@ class TestIOSets(TestCase): ...@@ -1405,6 +1408,47 @@ class TestIOSets(TestCase):
def _insertnoneraises(self): def _insertnoneraises(self):
self.t.insert(None) self.t.insert(None)
class TestIOSets(TestI_Sets):
def setUp(self):
self.t = IOSet()
class TestIOTreeSets(TestI_Sets):
def setUp(self):
self.t = IOTreeSet()
class TestIISets(TestI_Sets):
def setUp(self):
self.t = IISet()
class TestIITreeSets(TestI_Sets):
def setUp(self):
self.t = IITreeSet()
class TestLOSets(TestI_Sets):
def setUp(self):
self.t = LOSet()
class TestLOTreeSets(TestI_Sets):
def setUp(self):
self.t = LOTreeSet()
class TestLLSets(TestI_Sets):
def setUp(self):
self.t = LLSet()
class TestLLTreeSets(TestI_Sets):
def setUp(self):
self.t = LLTreeSet()
class DegenerateBTree(TestCase): class DegenerateBTree(TestCase):
# Build a degenerate tree (set). Boxes are BTree nodes. There are # Build a degenerate tree (set). Boxes are BTree nodes. There are
# 5 leaf buckets, each containing a single int. Keys in the BTree # 5 leaf buckets, each containing a single int. Keys in the BTree
...@@ -1758,7 +1802,6 @@ class BugFixes(TestCase): ...@@ -1758,7 +1802,6 @@ class BugFixes(TestCase):
self.assertEqual(len(t), 0) self.assertEqual(len(t), 0)
self.assertEqual(len(LP294788_ids), 0) self.assertEqual(len(LP294788_ids), 0)
class IIBTreeTest(BTreeTests): class IIBTreeTest(BTreeTests):
def setUp(self): def setUp(self):
self.t = IIBTree() self.t = IIBTree()
...@@ -2083,7 +2126,8 @@ def test_suite(): ...@@ -2083,7 +2126,8 @@ def test_suite():
# checking for assorted TypeErrors, and when both keys # checking for assorted TypeErrors, and when both keys
# and values are objects (OO), there's nothing to test. # and values are objects (OO), there's nothing to test.
TestIIBTrees, TestIFBTrees, TestIOBTrees, TestOIBTrees, TestIIBTrees, TestIFBTrees, TestIOBTrees, TestOIBTrees,
TestIOSets, TestIOSets, TestIOTreeSets, TestIISets, TestIITreeSets,
TestLOSets, TestLOTreeSets, TestLLSets, TestLLTreeSets,
DegenerateBTree, DegenerateBTree,
TestCmpError, TestCmpError,
BugFixes, BugFixes,
......
...@@ -17,6 +17,10 @@ Bugs Fixed ...@@ -17,6 +17,10 @@ Bugs Fixed
Fixes: https://bugs.launchpad.net/zodb/+bug/135108 Fixes: https://bugs.launchpad.net/zodb/+bug/135108
- BTree sets and tree sets didn't correctly check values passed to
update or to constructors, causing Python to exit under certain
circumstances.
3.9.5 (2010-04-23) 3.9.5 (2010-04-23)
================== ==================
......
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