]> granicus.if.org Git - python/commitdiff
Issue #15381: Try to fix refcount bug. Empty and 1-byte buffers are always shared.
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 3 Feb 2015 12:57:49 +0000 (14:57 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Tue, 3 Feb 2015 12:57:49 +0000 (14:57 +0200)
Modules/_io/bytesio.c

index ca5156b84ba735a564b733ddc9bc44fd4ad85e91..1638f943d0c128e85184c66077aa79099e860c4f 100644 (file)
@@ -38,7 +38,8 @@ typedef struct {
         return NULL; \
     }
 
-#define SHARED_BUF(self) (Py_REFCNT((self)->buf) > 1)
+#define SHARED_BUF(self) (Py_REFCNT((self)->buf) > 1 || \
+                          PyBytes_GET_SIZE((self)->buf) <= 1)
 
 
 /* Internal routine to get a line from the buffer of a BytesIO
@@ -308,6 +309,7 @@ read_bytes(bytesio *self, Py_ssize_t size)
     char *output;
 
     assert(self->buf != NULL);
+    assert(size <= self->string_size);
     if (size > 1 &&
         self->pos == 0 && size == PyBytes_GET_SIZE(self->buf) &&
         self->exports == 0) {