]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-20028: Keep original exception when PyUnicode_GetLength return -1 (GH-28832)
authorDong-hee Na <donghee.na@python.org>
Sat, 9 Oct 2021 15:16:12 +0000 (00:16 +0900)
committerGitHub <noreply@github.com>
Sat, 9 Oct 2021 15:16:12 +0000 (00:16 +0900)
Modules/_csv.c

index cfdfbce6e6824f675fb81a1d93bc4f433d98eedf..72f0791a4398b6f61a8eb972a8e7e3431baf0181 100644 (file)
@@ -244,6 +244,9 @@ _set_char_or_none(const char *name, Py_UCS4 *target, PyObject *src, Py_UCS4 dflt
                 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 @@ _set_char(const char *name, Py_UCS4 *target, PyObject *src, Py_UCS4 dflt)
                 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",