summaryrefslogtreecommitdiff
path: root/Python/marshal.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/marshal.c')
-rw-r--r--Python/marshal.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/Python/marshal.c b/Python/marshal.c
index 3e13851704..e519fc9bfa 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -979,20 +979,25 @@ r_object(RFILE *p)
retval = NULL;
break;
}
- buffer = PyMem_NEW(char, n);
- if (buffer == NULL) {
- retval = PyErr_NoMemory();
- break;
- }
- if (r_string(buffer, n, p) != n) {
+ if (n != 0) {
+ buffer = PyMem_NEW(char, n);
+ if (buffer == NULL) {
+ retval = PyErr_NoMemory();
+ break;
+ }
+ if (r_string(buffer, n, p) != n) {
+ PyMem_DEL(buffer);
+ PyErr_SetString(PyExc_EOFError,
+ "EOF read where object expected");
+ retval = NULL;
+ break;
+ }
+ v = PyUnicode_DecodeUTF8(buffer, n, "surrogatepass");
PyMem_DEL(buffer);
- PyErr_SetString(PyExc_EOFError,
- "EOF read where object expected");
- retval = NULL;
- break;
}
- v = PyUnicode_DecodeUTF8(buffer, n, "surrogatepass");
- PyMem_DEL(buffer);
+ else {
+ v = PyUnicode_New(0, 0);
+ }
if (type == TYPE_INTERNED)
PyUnicode_InternInPlace(&v);
retval = v;