Skip to content

Commit 94b866a

Browse files
committed
Handle os.listdir("") case correctly on Windows. Closes bug 500705.
1 parent 398b9f6 commit 94b866a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Modules/posixmodule.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -980,14 +980,15 @@ posix_listdir(PyObject *self, PyObject *args)
980980
char namebuf[MAX_PATH*2+5];
981981
char *bufptr = namebuf;
982982
int len = sizeof(namebuf)/sizeof(namebuf[0]);
983-
char ch;
984983

985984
if (!PyArg_ParseTuple(args, "et#:listdir",
986985
Py_FileSystemDefaultEncoding, &bufptr, &len))
987986
return NULL;
988-
ch = namebuf[len-1];
989-
if (ch != SEP && ch != ALTSEP && ch != ':')
990-
namebuf[len++] = '/';
987+
if (len > 0) {
988+
char ch = namebuf[len-1];
989+
if (ch != SEP && ch != ALTSEP && ch != ':')
990+
namebuf[len++] = '/';
991+
}
991992
strcpy(namebuf + len, "*.*");
992993

993994
if ((d = PyList_New(0)) == NULL)

0 commit comments

Comments
 (0)