Skip to content

Commit e920f0d

Browse files
committed
Reformulate 42903 using an if statement.
1 parent df44ab7 commit e920f0d

File tree

1 file changed

+31
-35
lines changed

1 file changed

+31
-35
lines changed

Modules/posixmodule.c

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,7 +1640,7 @@ posix_listdir(PyObject *self, PyObject *args)
16401640

16411641
PyObject *d, *v;
16421642
HANDLE hFindFile;
1643-
BOOL result = FALSE;
1643+
BOOL result;
16441644
WIN32_FIND_DATA FileData;
16451645
/* MAX_PATH characters could mean a bigger encoded string */
16461646
char namebuf[MAX_PATH*2+5];
@@ -1675,25 +1675,23 @@ posix_listdir(PyObject *self, PyObject *args)
16751675
return win32_error_unicode("FindFirstFileW", wnamebuf);
16761676
}
16771677
do {
1678-
if (wFileData.cFileName[0] == L'.' &&
1679-
(wFileData.cFileName[1] == L'\0' ||
1680-
wFileData.cFileName[1] == L'.' &&
1681-
wFileData.cFileName[2] == L'\0'))
1682-
goto loop_w;
1683-
v = PyUnicode_FromUnicode(wFileData.cFileName, wcslen(wFileData.cFileName));
1684-
if (v == NULL) {
1685-
Py_DECREF(d);
1686-
d = NULL;
1687-
break;
1688-
}
1689-
if (PyList_Append(d, v) != 0) {
1678+
/* Skip over . and .. */
1679+
if (wcscmp(wFileData.cFileName, L".") != 0 &&
1680+
wcscmp(wFileData.cFileName, L"..") != 0) {
1681+
v = PyUnicode_FromUnicode(wFileData.cFileName, wcslen(wFileData.cFileName));
1682+
if (v == NULL) {
1683+
Py_DECREF(d);
1684+
d = NULL;
1685+
break;
1686+
}
1687+
if (PyList_Append(d, v) != 0) {
1688+
Py_DECREF(v);
1689+
Py_DECREF(d);
1690+
d = NULL;
1691+
break;
1692+
}
16901693
Py_DECREF(v);
1691-
Py_DECREF(d);
1692-
d = NULL;
1693-
break;
16941694
}
1695-
Py_DECREF(v);
1696-
loop_w:
16971695
Py_BEGIN_ALLOW_THREADS
16981696
result = FindNextFileW(hFindFile, &wFileData);
16991697
Py_END_ALLOW_THREADS
@@ -1733,25 +1731,23 @@ posix_listdir(PyObject *self, PyObject *args)
17331731
return win32_error("FindFirstFile", namebuf);
17341732
}
17351733
do {
1736-
if (FileData.cFileName[0] == '.' &&
1737-
(FileData.cFileName[1] == '\0' ||
1738-
FileData.cFileName[1] == '.' &&
1739-
FileData.cFileName[2] == '\0'))
1740-
goto loop_a;
1741-
v = PyString_FromString(FileData.cFileName);
1742-
if (v == NULL) {
1743-
Py_DECREF(d);
1744-
d = NULL;
1745-
break;
1746-
}
1747-
if (PyList_Append(d, v) != 0) {
1734+
/* Skip over . and .. */
1735+
if (strcmp(FileData.cFileName, ".") != 0 &&
1736+
strcmp(FileData.cFileName, "..") != 0) {
1737+
v = PyString_FromString(FileData.cFileName);
1738+
if (v == NULL) {
1739+
Py_DECREF(d);
1740+
d = NULL;
1741+
break;
1742+
}
1743+
if (PyList_Append(d, v) != 0) {
1744+
Py_DECREF(v);
1745+
Py_DECREF(d);
1746+
d = NULL;
1747+
break;
1748+
}
17481749
Py_DECREF(v);
1749-
Py_DECREF(d);
1750-
d = NULL;
1751-
break;
17521750
}
1753-
Py_DECREF(v);
1754-
loop_a:
17551751
Py_BEGIN_ALLOW_THREADS
17561752
result = FindNextFile(hFindFile, &FileData);
17571753
Py_END_ALLOW_THREADS

0 commit comments

Comments
 (0)