diff options
author | Steve Dower <steve.dower@python.org> | 2021-12-11 13:43:40 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-11 13:43:40 (GMT) |
commit | 971ece8e1738b1107dda692cc44c6d8ddce384cd (patch) | |
tree | 13cb2af42b9c86d0131767ed0d176059de319a38 /Modules/getpath.c | |
parent | 4fe5585240f64c3d14eb635ff82b163f92074b3a (diff) | |
download | cpython-971ece8e1738b1107dda692cc44c6d8ddce384cd.zip cpython-971ece8e1738b1107dda692cc44c6d8ddce384cd.tar.gz cpython-971ece8e1738b1107dda692cc44c6d8ddce384cd.tar.bz2 |
bpo-46048: Fix parsing of single character lines in getpath readlines() (GH-30048)
Diffstat (limited to 'Modules/getpath.c')
-rw-r--r-- | Modules/getpath.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/Modules/getpath.c b/Modules/getpath.c index fedb41c..3adce46 100644 --- a/Modules/getpath.c +++ b/Modules/getpath.c @@ -386,11 +386,11 @@ getpath_readlines(PyObject *Py_UNUSED(self), PyObject *args) wchar_t *p1 = wbuffer; wchar_t *p2 = p1; while ((p2 = wcschr(p1, L'\n')) != NULL) { - size_t cb = p2 - p1; - while (cb && (p1[cb] == L'\n' || p1[cb] == L'\r')) { + Py_ssize_t cb = p2 - p1; + while (cb >= 0 && (p1[cb] == L'\n' || p1[cb] == L'\r')) { --cb; } - PyObject *u = PyUnicode_FromWideChar(p1, cb ? cb + 1 : 0); + PyObject *u = PyUnicode_FromWideChar(p1, cb >= 0 ? cb + 1 : 0); if (!u || PyList_Append(r, u) < 0) { Py_XDECREF(u); Py_CLEAR(r); |