]> granicus.if.org Git - python/commitdiff
The NULL pointer for empty strings turns out to be a pain.
authorGuido van Rossum <guido@python.org>
Wed, 9 May 2007 23:36:14 +0000 (23:36 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 9 May 2007 23:36:14 +0000 (23:36 +0000)
At least for the buffer API, return "" in that case.

Objects/bytesobject.c

index a07f9e709b68fd0ed6238ab06ef599079d196b32..2cdaf377680ba8576e47ae3232d33385ef43157d 100644 (file)
@@ -950,7 +950,10 @@ bytes_getbuffer(PyBytesObject *self, Py_ssize_t index, const void **ptr)
                         "accessing non-existent bytes segment");
         return -1;
     }
-    *ptr = (void *)self->ob_bytes;
+    if (self->ob_bytes == NULL)
+        *ptr = "";
+    else
+        *ptr = self->ob_bytes;
     return self->ob_size;
 }