[3.10] bpo-20028: Keep original exception when PyUnicode_GetLength return -1 (GH-28832) (GH-28834)
diff --git a/Modules/_csv.c b/Modules/_csv.c
index cfdfbce..72f0791 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -244,6 +244,9 @@
return -1;
}
Py_ssize_t len = PyUnicode_GetLength(src);
+ if (len < 0) {
+ return -1;
+ }
if (len > 1) {
PyErr_Format(PyExc_TypeError,
"\"%s\" must be a 1-character string",
@@ -274,6 +277,9 @@
return -1;
}
Py_ssize_t len = PyUnicode_GetLength(src);
+ if (len < 0) {
+ return -1;
+ }
if (len > 1) {
PyErr_Format(PyExc_TypeError,
"\"%s\" must be a 1-character string",