Skip to content

Commit c4f281e

Browse files
author
Victor Stinner
committed
Fix misuse of PyUnicode_GET_SIZE, use PyUnicode_GET_LENGTH instead
1 parent ed2682b commit c4f281e

6 files changed

Lines changed: 10 additions & 12 deletions

File tree

Modules/_cursesmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2719,7 +2719,7 @@ PyCurses_ConvertToWchar_t(PyObject *obj,
27192719
PyErr_Format(PyExc_TypeError,
27202720
"expect bytes or str of length 1, or int, "
27212721
"got a str of length %zi",
2722-
PyUnicode_GET_SIZE(obj));
2722+
PyUnicode_GET_LENGTH(obj));
27232723
return 0;
27242724
}
27252725
*wch = buffer[0];

Modules/_io/stringio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ stringio_iternext(stringio *self)
343343
if (line == NULL)
344344
return NULL;
345345

346-
if (PyUnicode_GET_SIZE(line) == 0) {
346+
if (PyUnicode_GET_LENGTH(line) == 0) {
347347
/* Reached EOF */
348348
Py_DECREF(line);
349349
return NULL;

Modules/_json.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ _parse_constant(PyScannerObject *s, char *constant, Py_ssize_t idx, Py_ssize_t *
837837

838838
/* rval = parse_constant(constant) */
839839
rval = PyObject_CallFunctionObjArgs(s->parse_constant, cstr, NULL);
840-
idx += PyUnicode_GET_SIZE(cstr);
840+
idx += PyUnicode_GET_LENGTH(cstr);
841841
Py_DECREF(cstr);
842842
*next_idx_ptr = idx;
843843
return rval;

Modules/syslogmodule.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,16 @@ syslog_get_argv(void)
9090
if (!PyUnicode_Check(scriptobj)) {
9191
return(NULL);
9292
}
93-
scriptlen = PyUnicode_GET_SIZE(scriptobj);
93+
scriptlen = PyUnicode_GET_LENGTH(scriptobj);
9494
if (scriptlen == 0) {
9595
return(NULL);
9696
}
9797

98-
slash = PyUnicode_FindChar(scriptobj, SEP,
99-
0, PyUnicode_GET_LENGTH(scriptobj), -1);
98+
slash = PyUnicode_FindChar(scriptobj, SEP, 0, scriptlen, -1);
10099
if (slash == -2)
101100
return NULL;
102101
if (slash != -1) {
103-
return PyUnicode_Substring(scriptobj, slash,
104-
PyUnicode_GET_LENGTH(scriptobj));
102+
return PyUnicode_Substring(scriptobj, slash, scriptlen);
105103
} else {
106104
Py_INCREF(scriptobj);
107105
return(scriptobj);

Objects/unicodeobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12181,7 +12181,7 @@ unicode_maketrans(PyUnicodeObject *null, PyObject *args)
1218112181
if (z != NULL) {
1218212182
z_kind = PyUnicode_KIND(z);
1218312183
z_data = PyUnicode_DATA(z);
12184-
for (i = 0; i < PyUnicode_GET_SIZE(z); i++) {
12184+
for (i = 0; i < PyUnicode_GET_LENGTH(z); i++) {
1218512185
key = PyLong_FromLong(PyUnicode_READ(z_kind, z_data, i));
1218612186
if (!key)
1218712187
goto err;
@@ -12206,7 +12206,7 @@ unicode_maketrans(PyUnicodeObject *null, PyObject *args)
1220612206
if (PyUnicode_Check(key)) {
1220712207
/* convert string keys to integer keys */
1220812208
PyObject *newkey;
12209-
if (PyUnicode_GET_SIZE(key) != 1) {
12209+
if (PyUnicode_GET_LENGTH(key) != 1) {
1221012210
PyErr_SetString(PyExc_ValueError, "string keys in translate "
1221112211
"table must be of length 1");
1221212212
goto err;
@@ -13694,7 +13694,7 @@ unicodeiter_len(unicodeiterobject *it)
1369413694
{
1369513695
Py_ssize_t len = 0;
1369613696
if (it->it_seq)
13697-
len = PyUnicode_GET_SIZE(it->it_seq) - it->it_index;
13697+
len = PyUnicode_GET_LENGTH(it->it_seq) - it->it_index;
1369813698
return PyLong_FromSsize_t(len);
1369913699
}
1370013700

Python/formatter_unicode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ format_string_internal(PyObject *value, const InternalFormatSpec *format)
693693
Py_ssize_t rpad;
694694
Py_ssize_t total;
695695
Py_ssize_t pos;
696-
Py_ssize_t len = PyUnicode_GET_SIZE(value);
696+
Py_ssize_t len = PyUnicode_GET_LENGTH(value);
697697
PyObject *result = NULL;
698698
int maxchar = 127;
699699

0 commit comments

Comments
 (0)