Skip to content

Commit ec04db7

Browse files
authored
bpo-20028: Keep original exception when PyUnicode_GetLength return -1 (GH-28832)
1 parent 34bbc87 commit ec04db7

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Modules/_csv.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ _set_char_or_none(const char *name, Py_UCS4 *target, PyObject *src, Py_UCS4 dflt
244244
return -1;
245245
}
246246
Py_ssize_t len = PyUnicode_GetLength(src);
247+
if (len < 0) {
248+
return -1;
249+
}
247250
if (len > 1) {
248251
PyErr_Format(PyExc_TypeError,
249252
"\"%s\" must be a 1-character string",
@@ -274,6 +277,9 @@ _set_char(const char *name, Py_UCS4 *target, PyObject *src, Py_UCS4 dflt)
274277
return -1;
275278
}
276279
Py_ssize_t len = PyUnicode_GetLength(src);
280+
if (len < 0) {
281+
return -1;
282+
}
277283
if (len > 1) {
278284
PyErr_Format(PyExc_TypeError,
279285
"\"%s\" must be a 1-character string",

0 commit comments

Comments
 (0)