From: Neil Schemenauer Date: Fri, 22 Mar 2002 20:51:58 +0000 (+0000) Subject: Handle os.listdir("") case correctly on Windows. Closes bug 500705. X-Git-Tag: v2.3c1~6395 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=94b866a03088da6257823c74a71b4d0760c60bbb;p=python Handle os.listdir("") case correctly on Windows. Closes bug 500705. --- diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 4d9408a024..46e145f484 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -980,14 +980,15 @@ posix_listdir(PyObject *self, PyObject *args) char namebuf[MAX_PATH*2+5]; char *bufptr = namebuf; int len = sizeof(namebuf)/sizeof(namebuf[0]); - char ch; if (!PyArg_ParseTuple(args, "et#:listdir", Py_FileSystemDefaultEncoding, &bufptr, &len)) return NULL; - ch = namebuf[len-1]; - if (ch != SEP && ch != ALTSEP && ch != ':') - namebuf[len++] = '/'; + if (len > 0) { + char ch = namebuf[len-1]; + if (ch != SEP && ch != ALTSEP && ch != ':') + namebuf[len++] = '/'; + } strcpy(namebuf + len, "*.*"); if ((d = PyList_New(0)) == NULL)