]> granicus.if.org Git - python/commitdiff
Issue #5913: os.listdir() should fail for empty path on windows.
authorHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
Mon, 4 May 2009 05:28:39 +0000 (05:28 +0000)
committerHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
Mon, 4 May 2009 05:28:39 +0000 (05:28 +0000)
Misc/NEWS
Modules/posixmodule.c

index e372a623609a8fd6818c49e4aae9c28d598a4171..6b7a94d320a9af8dc9b431b00b032cfb758f7aae 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -266,6 +266,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #5913: os.listdir() should fail for empty path on windows.
+
 - Issue #5084: unpickling now interns the attribute names of pickled objects,
   saving memory and avoiding growth in size of subsequent pickles. Proposal
   and original patch by Jake McGuire.
index 7a96300e2502e47fbe69c993f619269abdb62bac..511b3854e38292985ec076d9b5438669120205b5 100644 (file)
@@ -2183,7 +2183,6 @@ posix_listdir(PyObject *self, PyObject *args)
                if (PyArg_ParseTuple(args, "U:listdir", &po)) {
                        WIN32_FIND_DATAW wFileData;
                        Py_UNICODE *wnamebuf;
-                       Py_UNICODE wch;
                        /* Overallocate for \\*.*\0 */
                        len = PyUnicode_GET_SIZE(po);
                        wnamebuf = malloc((len + 5) * sizeof(wchar_t));
@@ -2192,10 +2191,12 @@ posix_listdir(PyObject *self, PyObject *args)
                                return NULL;
                        }
                        wcscpy(wnamebuf, PyUnicode_AS_UNICODE(po));
-                       wch = len > 0 ? wnamebuf[len-1] : '\0';
-                       if (wch != L'/' && wch != L'\\' && wch != L':')
-                               wnamebuf[len++] = L'\\';
-                       wcscpy(wnamebuf + len, L"*.*");
+                       if (len > 0) {
+                               Py_UNICODE wch = wnamebuf[len-1];
+                               if (wch != L'/' && wch != L'\\' && wch != L':')
+                                       wnamebuf[len++] = L'\\';
+                               wcscpy(wnamebuf + len, L"*.*");
+                       }
                        if ((d = PyList_New(0)) == NULL) {
                                free(wnamebuf);
                                return NULL;
@@ -2266,8 +2267,8 @@ posix_listdir(PyObject *self, PyObject *args)
                char ch = namebuf[len-1];
                if (ch != SEP && ch != ALTSEP && ch != ':')
                        namebuf[len++] = '/';
+               strcpy(namebuf + len, "*.*");
        }
-       strcpy(namebuf + len, "*.*");
 
        if ((d = PyList_New(0)) == NULL)
                return NULL;