Antoine Pitrou <pit...@free.fr> added the comment:

This is because of the buffer pointer passed to the codecs machinery being NULL 
when the empty string is being decoded.

Quick patch follows (needs a test). Also, it is not clear whether it is allowed 
to store a NULL pointer in the "buf" member of a Py_buffer when the length is 
0. Nick, Mark?


Index: Objects/unicodeobject.c
===================================================================
--- Objects/unicodeobject.c     (révision 88500)
+++ Objects/unicodeobject.c     (copie de travail)
@@ -1460,6 +1460,7 @@
     PyObject *buffer = NULL, *unicode;
     Py_buffer info;
     char lower[11];  /* Enough for any encoding shortcut */
+    static const char empty[] = "";
 
     if (encoding == NULL)
         encoding = PyUnicode_GetDefaultEncoding();
@@ -1485,6 +1486,8 @@
 
     /* Decode via the codec registry */
     buffer = NULL;
+    if (s == NULL)
+        s = empty;
     if (PyBuffer_FillInfo(&info, NULL, (void *)s, size, 1, PyBUF_FULL_RO) < 0)
         goto onError;
     buffer = PyMemoryView_FromBuffer(&info);

----------
nosy: +mark.dickinson, ncoghlan

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue11286>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to