mirror of https://github.com/python/cpython
bpo-33954: Fix compiler warning in _PyUnicode_FastFill() (GH-10737)
'data' argument of unicode_fill() is modified, so it must not be constant. Add more assertions to unicode_fill(): check the maximum character value.
This commit is contained in:
parent
cfaafda8e3
commit
163403a63e
|
@ -228,12 +228,14 @@ unicode_fill(enum PyUnicode_Kind kind, void *data, Py_UCS4 value,
|
||||||
assert(kind != PyUnicode_WCHAR_KIND);
|
assert(kind != PyUnicode_WCHAR_KIND);
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case PyUnicode_1BYTE_KIND: {
|
case PyUnicode_1BYTE_KIND: {
|
||||||
|
assert(value <= 0xff);
|
||||||
Py_UCS1 ch = (unsigned char)value;
|
Py_UCS1 ch = (unsigned char)value;
|
||||||
Py_UCS1 *to = (Py_UCS1 *)data + start;
|
Py_UCS1 *to = (Py_UCS1 *)data + start;
|
||||||
memset(to, ch, length);
|
memset(to, ch, length);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PyUnicode_2BYTE_KIND: {
|
case PyUnicode_2BYTE_KIND: {
|
||||||
|
assert(value <= 0xffff);
|
||||||
Py_UCS2 ch = (Py_UCS2)value;
|
Py_UCS2 ch = (Py_UCS2)value;
|
||||||
Py_UCS2 *to = (Py_UCS2 *)data + start;
|
Py_UCS2 *to = (Py_UCS2 *)data + start;
|
||||||
const Py_UCS2 *end = to + length;
|
const Py_UCS2 *end = to + length;
|
||||||
|
@ -241,6 +243,7 @@ unicode_fill(enum PyUnicode_Kind kind, void *data, Py_UCS4 value,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PyUnicode_4BYTE_KIND: {
|
case PyUnicode_4BYTE_KIND: {
|
||||||
|
assert(value <= MAX_UNICODE);
|
||||||
Py_UCS4 ch = value;
|
Py_UCS4 ch = value;
|
||||||
Py_UCS4 * to = (Py_UCS4 *)data + start;
|
Py_UCS4 * to = (Py_UCS4 *)data + start;
|
||||||
const Py_UCS4 *end = to + length;
|
const Py_UCS4 *end = to + length;
|
||||||
|
@ -10117,7 +10120,7 @@ _PyUnicode_FastFill(PyObject *unicode, Py_ssize_t start, Py_ssize_t length,
|
||||||
Py_UCS4 fill_char)
|
Py_UCS4 fill_char)
|
||||||
{
|
{
|
||||||
const enum PyUnicode_Kind kind = PyUnicode_KIND(unicode);
|
const enum PyUnicode_Kind kind = PyUnicode_KIND(unicode);
|
||||||
const void *data = PyUnicode_DATA(unicode);
|
void *data = PyUnicode_DATA(unicode);
|
||||||
assert(PyUnicode_IS_READY(unicode));
|
assert(PyUnicode_IS_READY(unicode));
|
||||||
assert(unicode_modifiable(unicode));
|
assert(unicode_modifiable(unicode));
|
||||||
assert(fill_char <= PyUnicode_MAX_CHAR_VALUE(unicode));
|
assert(fill_char <= PyUnicode_MAX_CHAR_VALUE(unicode));
|
||||||
|
|
Loading…
Reference in New Issue