mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Check whether a string resize is necessary at the end
of PyString_DecodeEscape(). This prevents a call to _PyString_Resize() for the empty string, which would result in a PyErr_BadInternalCall(), because the empty string has more than one reference. This closes SF bug http://www.python.org/sf/603937
This commit is contained in:
parent
8e790e7007
commit
8709a420c4
2 changed files with 12 additions and 4 deletions
|
@ -533,8 +533,8 @@ PyObject *PyString_DecodeEscape(const char *s,
|
|||
char *p, *buf;
|
||||
const char *end;
|
||||
PyObject *v;
|
||||
v = PyString_FromStringAndSize((char *)NULL,
|
||||
recode_encoding ? 4*len:len);
|
||||
int newlen = recode_encoding ? 4*len:len;
|
||||
v = PyString_FromStringAndSize((char *)NULL, newlen);
|
||||
if (v == NULL)
|
||||
return NULL;
|
||||
p = buf = PyString_AsString(v);
|
||||
|
@ -660,7 +660,8 @@ PyObject *PyString_DecodeEscape(const char *s,
|
|||
break;
|
||||
}
|
||||
}
|
||||
_PyString_Resize(&v, (int)(p - buf));
|
||||
if (p-buf < newlen)
|
||||
_PyString_Resize(&v, (int)(p - buf));
|
||||
return v;
|
||||
failed:
|
||||
Py_DECREF(v);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue