Skip to content

Commit de530fe

Browse files
Fix f_519
1 parent 7109d24 commit de530fe

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/port.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ void* WS_CreateFileA(const char* fileName, unsigned long desiredAccess,
267267
void* WS_FindFirstFileA(const char* fileName,
268268
char* realFileName, size_t realFileNameSz, int* isDir, void* heap)
269269
{
270-
HANDLE findHandle = NULL;
270+
HANDLE findHandle = INVALID_HANDLE_VALUE;
271271
WIN32_FIND_DATAW findFileData;
272272
wchar_t* unicodeFileName;
273273
size_t unicodeFileNameSz = 0;
@@ -295,12 +295,14 @@ void* WS_FindFirstFileA(const char* fileName,
295295

296296
WFREE(unicodeFileName, heap, PORT_DYNTYPE_STRING);
297297

298-
error = wcstombs_s(NULL, realFileName, realFileNameSz,
299-
findFileData.cFileName, realFileNameSz);
298+
if (findHandle != INVALID_HANDLE_VALUE) {
299+
error = wcstombs_s(NULL, realFileName, realFileNameSz,
300+
findFileData.cFileName, realFileNameSz);
300301

301-
if (isDir != NULL) {
302-
*isDir =
303-
(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
302+
if (isDir != NULL) {
303+
*isDir =
304+
(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
305+
}
304306
}
305307

306308
return (void*)findHandle;

0 commit comments

Comments
 (0)