Skip to content

Commit 163403a

Browse files
authored
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.
1 parent cfaafda commit 163403a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Objects/unicodeobject.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,19 +228,22 @@ unicode_fill(enum PyUnicode_Kind kind, void *data, Py_UCS4 value,
228228
assert(kind != PyUnicode_WCHAR_KIND);
229229
switch (kind) {
230230
case PyUnicode_1BYTE_KIND: {
231+
assert(value <= 0xff);
231232
Py_UCS1 ch = (unsigned char)value;
232233
Py_UCS1 *to = (Py_UCS1 *)data + start;
233234
memset(to, ch, length);
234235
break;
235236
}
236237
case PyUnicode_2BYTE_KIND: {
238+
assert(value <= 0xffff);
237239
Py_UCS2 ch = (Py_UCS2)value;
238240
Py_UCS2 *to = (Py_UCS2 *)data + start;
239241
const Py_UCS2 *end = to + length;
240242
for (; to < end; ++to) *to = ch;
241243
break;
242244
}
243245
case PyUnicode_4BYTE_KIND: {
246+
assert(value <= MAX_UNICODE);
244247
Py_UCS4 ch = value;
245248
Py_UCS4 * to = (Py_UCS4 *)data + start;
246249
const Py_UCS4 *end = to + length;
@@ -10117,7 +10120,7 @@ _PyUnicode_FastFill(PyObject *unicode, Py_ssize_t start, Py_ssize_t length,
1011710120
Py_UCS4 fill_char)
1011810121
{
1011910122
const enum PyUnicode_Kind kind = PyUnicode_KIND(unicode);
10120-
const void *data = PyUnicode_DATA(unicode);
10123+
void *data = PyUnicode_DATA(unicode);
1012110124
assert(PyUnicode_IS_READY(unicode));
1012210125
assert(unicode_modifiable(unicode));
1012310126
assert(fill_char <= PyUnicode_MAX_CHAR_VALUE(unicode));

0 commit comments

Comments
 (0)