mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
On c.l.py, Martin v. Löwis said that Py_UNICODE could be of a signed type,
so fiddle Jeremy's fix to live with that. Also added more comments. Bugfix candidate (this bug is in all versions of Python, at least since 2.1).
This commit is contained in:
parent
d808279be3
commit
ced69f8a20
1 changed files with 145 additions and 137 deletions
|
@ -132,8 +132,12 @@ int unicode_resize(register PyUnicodeObject *unicode,
|
|||
instead ! */
|
||||
if (unicode == unicode_empty ||
|
||||
(unicode->length == 1 &&
|
||||
/* XXX Is unicode->str[] always unsigned? */
|
||||
unicode->str[0] < 256U &&
|
||||
/* MvL said unicode->str[] may be signed. Python generally assumes
|
||||
* an int contains at least 32 bits, and we don't use more than
|
||||
* 32 bits even in a UCS4 build, so casting to unsigned int should
|
||||
* be correct.
|
||||
*/
|
||||
(unsigned int)unicode->str[0] < 256U &&
|
||||
unicode_latin1[unicode->str[0]] == unicode)) {
|
||||
PyErr_SetString(PyExc_SystemError,
|
||||
"can't resize shared unicode objects");
|
||||
|
@ -176,7 +180,7 @@ PyUnicodeObject *_PyUnicode_New(int length)
|
|||
{
|
||||
register PyUnicodeObject *unicode;
|
||||
|
||||
/* Optimization for empty strings */
|
||||
/* Optimization fo empty strings */
|
||||
if (length == 0 && unicode_empty != NULL) {
|
||||
Py_INCREF(unicode_empty);
|
||||
return unicode_empty;
|
||||
|
@ -213,7 +217,11 @@ PyUnicodeObject *_PyUnicode_New(int length)
|
|||
goto onError;
|
||||
}
|
||||
/* Initialize the first element to guard against cases where
|
||||
the caller fails before initializing str.
|
||||
* the caller fails before initializing str -- unicode_resize()
|
||||
* reads str[0], and the Keep-Alive optimization can keep memory
|
||||
* allocated for str alive across a call to unicode_dealloc(unicode).
|
||||
* We don't want unicode_resize to read uninitialized memory in
|
||||
* that case.
|
||||
*/
|
||||
unicode->str[0] = 0;
|
||||
unicode->str[length] = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue