Skip to content

Commit

Permalink
Fit the 'repr' of bucket objects.
Browse files Browse the repository at this point in the history
Broeken version could contain garbage characters.
  • Loading branch information
tseaver committed Jan 15, 2013
1 parent 7d84f2f commit c48e400
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions BTrees/BucketTemplate.c
Expand Up @@ -1840,9 +1840,9 @@ bucket_repr(Bucket *self)
{
Py_DECREF(r);
#ifdef PY3K
return PyUnicode_DecodeLatin1(repr, sizeof(repr), "surrogateescape");
return PyUnicode_DecodeLatin1(repr, strlen(repr), "surrogateescape");
#else
return PyBytes_FromStringAndSize(repr, sizeof(repr));
return PyBytes_FromStringAndSize(repr, strlen(repr));
#endif
}
else
Expand Down
12 changes: 12 additions & 0 deletions BTrees/tests/common.py
Expand Up @@ -202,6 +202,18 @@ def _populate(self, t, l):
for i in range(l):
t[i]=i

def testShortRepr(self):
# test the repr because buckets have a complex repr implementation
# internally the cutoff from a stack allocated buffer to a heap
# allocated buffer is 10000.
t = self._makeOne()
for i in range(5):
t[i] = i
r = repr(t)
# Make sure the repr is **not* 10000 bytes long for a shrort bucket.
# (the buffer must be terminated when copied).
self.assertTrue(len(r) < 10000)

def testRepr(self):
# test the repr because buckets have a complex repr implementation
# internally the cutoff from a stack allocated buffer to a heap
Expand Down
3 changes: 2 additions & 1 deletion CHANGES.rst
Expand Up @@ -5,7 +5,8 @@
4.0.5 (unreleased)
------------------

- TBD
- Fit the ``repr`` of bucket objects, which could contain garbage
characters.


4.0.4 (2013-01-12)
Expand Down

0 comments on commit c48e400

Please sign in to comment.