Skip to content

Commit bbb9be7

Browse files
author
Hirokazu Yamamoto
committed
Merged revisions 72273 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r72273 | hirokazu.yamamoto | 2009-05-04 14:28:39 +0900 | 1 line Issue #5913: os.listdir() should fail for empty path on windows. ........
1 parent 73e8e5f commit bbb9be7

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ Installation
109109
Library
110110
-------
111111

112+
- Issue #5913: os.listdir() should fail for empty path on windows.
113+
112114
- Issue #5084: unpickling now interns the attribute names of pickled objects,
113115
saving memory and avoiding growth in size of subsequent pickles. Proposal
114116
and original patch by Jake McGuire.

Modules/posixmodule.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,7 +2183,6 @@ posix_listdir(PyObject *self, PyObject *args)
21832183
if (PyArg_ParseTuple(args, "U:listdir", &po)) {
21842184
WIN32_FIND_DATAW wFileData;
21852185
Py_UNICODE *wnamebuf;
2186-
Py_UNICODE wch;
21872186
/* Overallocate for \\*.*\0 */
21882187
len = PyUnicode_GET_SIZE(po);
21892188
wnamebuf = malloc((len + 5) * sizeof(wchar_t));
@@ -2192,10 +2191,12 @@ posix_listdir(PyObject *self, PyObject *args)
21922191
return NULL;
21932192
}
21942193
wcscpy(wnamebuf, PyUnicode_AS_UNICODE(po));
2195-
wch = len > 0 ? wnamebuf[len-1] : '\0';
2196-
if (wch != L'/' && wch != L'\\' && wch != L':')
2197-
wnamebuf[len++] = L'\\';
2198-
wcscpy(wnamebuf + len, L"*.*");
2194+
if (len > 0) {
2195+
Py_UNICODE wch = wnamebuf[len-1];
2196+
if (wch != L'/' && wch != L'\\' && wch != L':')
2197+
wnamebuf[len++] = L'\\';
2198+
wcscpy(wnamebuf + len, L"*.*");
2199+
}
21992200
if ((d = PyList_New(0)) == NULL) {
22002201
free(wnamebuf);
22012202
return NULL;
@@ -2266,8 +2267,8 @@ posix_listdir(PyObject *self, PyObject *args)
22662267
char ch = namebuf[len-1];
22672268
if (ch != SEP && ch != ALTSEP && ch != ':')
22682269
namebuf[len++] = '/';
2270+
strcpy(namebuf + len, "*.*");
22692271
}
2270-
strcpy(namebuf + len, "*.*");
22712272

22722273
if ((d = PyList_New(0)) == NULL)
22732274
return NULL;

0 commit comments

Comments
 (0)