Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 51ab414

Browse files
committed
Change PyUnicode_EncodeUTF7() to return a bytes object.
1 parent ce32db3 commit 51ab414

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

Objects/unicodeobject.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,13 +1149,13 @@ PyObject *PyUnicode_EncodeUTF7(const Py_UNICODE *s,
11491149
char * start;
11501150

11511151
if (size == 0)
1152-
return PyString_FromStringAndSize(NULL, 0);
1152+
return PyBytes_FromStringAndSize(NULL, 0);
11531153

1154-
v = PyString_FromStringAndSize(NULL, cbAllocated);
1154+
v = PyBytes_FromStringAndSize(NULL, cbAllocated);
11551155
if (v == NULL)
11561156
return NULL;
11571157

1158-
start = out = PyString_AS_STRING(v);
1158+
start = out = PyBytes_AS_STRING(v);
11591159
for (;i < size; ++i) {
11601160
Py_UNICODE ch = s[i];
11611161

@@ -1221,7 +1221,10 @@ PyObject *PyUnicode_EncodeUTF7(const Py_UNICODE *s,
12211221
*out++ = '-';
12221222
}
12231223

1224-
_PyString_Resize(&v, out - start);
1224+
if (PyBytes_Resize(v, out - start)) {
1225+
Py_DECREF(v);
1226+
return NULL;
1227+
}
12251228
return v;
12261229
}
12271230

0 commit comments

Comments
 (0)