mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Fixed a couple of instances where a 0-length string was being
resized after creation. 0-length strings are usually shared and _PyString_Resize() fails on these shared strings. Fixes [ Bug #111667 ] unicode core dump.
This commit is contained in:
parent
673c6cf3d4
commit
b7520774e2
1 changed files with 13 additions and 6 deletions
|
@ -842,7 +842,7 @@ PyObject *PyUnicode_EncodeUTF8(const Py_UNICODE *s,
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
goto done;
|
return v;
|
||||||
|
|
||||||
p = q = PyString_AS_STRING(v);
|
p = q = PyString_AS_STRING(v);
|
||||||
while (i < size) {
|
while (i < size) {
|
||||||
|
@ -892,8 +892,6 @@ PyObject *PyUnicode_EncodeUTF8(const Py_UNICODE *s,
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
if (_PyString_Resize(&v, p - q))
|
if (_PyString_Resize(&v, p - q))
|
||||||
goto onError;
|
goto onError;
|
||||||
|
|
||||||
done:
|
|
||||||
return v;
|
return v;
|
||||||
|
|
||||||
onError:
|
onError:
|
||||||
|
@ -1082,7 +1080,7 @@ PyObject *PyUnicode_EncodeUTF16(const Py_UNICODE *s,
|
||||||
if (byteorder == 0)
|
if (byteorder == 0)
|
||||||
*p++ = 0xFEFF;
|
*p++ = 0xFEFF;
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
goto done;
|
return v;
|
||||||
if (byteorder == 0 ||
|
if (byteorder == 0 ||
|
||||||
#ifdef BYTEORDER_IS_LITTLE_ENDIAN
|
#ifdef BYTEORDER_IS_LITTLE_ENDIAN
|
||||||
byteorder == -1
|
byteorder == -1
|
||||||
|
@ -1096,7 +1094,6 @@ PyObject *PyUnicode_EncodeUTF16(const Py_UNICODE *s,
|
||||||
Py_UNICODE ch = *s++;
|
Py_UNICODE ch = *s++;
|
||||||
*p++ = (ch >> 8) | (ch << 8);
|
*p++ = (ch >> 8) | (ch << 8);
|
||||||
}
|
}
|
||||||
done:
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1563,6 +1560,8 @@ PyObject *PyUnicode_EncodeRawUnicodeEscape(const Py_UNICODE *s,
|
||||||
repr = PyString_FromStringAndSize(NULL, 6 * size);
|
repr = PyString_FromStringAndSize(NULL, 6 * size);
|
||||||
if (repr == NULL)
|
if (repr == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if (size == 0)
|
||||||
|
return repr;
|
||||||
|
|
||||||
p = q = PyString_AS_STRING(repr);
|
p = q = PyString_AS_STRING(repr);
|
||||||
while (size-- > 0) {
|
while (size-- > 0) {
|
||||||
|
@ -1662,9 +1661,12 @@ PyObject *PyUnicode_EncodeLatin1(const Py_UNICODE *p,
|
||||||
{
|
{
|
||||||
PyObject *repr;
|
PyObject *repr;
|
||||||
char *s, *start;
|
char *s, *start;
|
||||||
|
|
||||||
repr = PyString_FromStringAndSize(NULL, size);
|
repr = PyString_FromStringAndSize(NULL, size);
|
||||||
if (repr == NULL)
|
if (repr == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if (size == 0)
|
||||||
|
return repr;
|
||||||
|
|
||||||
s = PyString_AS_STRING(repr);
|
s = PyString_AS_STRING(repr);
|
||||||
start = s;
|
start = s;
|
||||||
|
@ -1802,9 +1804,12 @@ PyObject *PyUnicode_EncodeASCII(const Py_UNICODE *p,
|
||||||
{
|
{
|
||||||
PyObject *repr;
|
PyObject *repr;
|
||||||
char *s, *start;
|
char *s, *start;
|
||||||
|
|
||||||
repr = PyString_FromStringAndSize(NULL, size);
|
repr = PyString_FromStringAndSize(NULL, size);
|
||||||
if (repr == NULL)
|
if (repr == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if (size == 0)
|
||||||
|
return repr;
|
||||||
|
|
||||||
s = PyString_AS_STRING(repr);
|
s = PyString_AS_STRING(repr);
|
||||||
start = s;
|
start = s;
|
||||||
|
@ -1890,7 +1895,7 @@ PyObject *PyUnicode_EncodeMBCS(const Py_UNICODE *p,
|
||||||
repr = PyString_FromStringAndSize(NULL, mbcssize);
|
repr = PyString_FromStringAndSize(NULL, mbcssize);
|
||||||
if (repr == NULL)
|
if (repr == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (mbcssize==0)
|
if (mbcssize == 0)
|
||||||
return repr;
|
return repr;
|
||||||
|
|
||||||
/* Do the conversion */
|
/* Do the conversion */
|
||||||
|
@ -2067,6 +2072,8 @@ PyObject *PyUnicode_EncodeCharmap(const Py_UNICODE *p,
|
||||||
v = PyString_FromStringAndSize(NULL, size);
|
v = PyString_FromStringAndSize(NULL, size);
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if (size == 0)
|
||||||
|
return v;
|
||||||
s = PyString_AS_STRING(v);
|
s = PyString_AS_STRING(v);
|
||||||
while (size-- > 0) {
|
while (size-- > 0) {
|
||||||
Py_UNICODE ch = *p++;
|
Py_UNICODE ch = *p++;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue