mirror of
https://github.com/python/cpython.git
synced 2025-08-23 10:16:01 +00:00
bpo-46048: Fix parsing of single character lines in getpath readlines() (GH-30048)
This commit is contained in:
parent
4fe5585240
commit
971ece8e17
3 changed files with 25 additions and 3 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue