Skip to content

Commit

Permalink
Fix e7c3d2f on Windows
Browse files Browse the repository at this point in the history
Code now relies on being able to copy struct dirents, but our Windows
emulation library used a pointer to a static buffer for the filename,
which was overwritten while iterating over the directory. Now fixed by
replacing it with a static buffer in struct dirent, as Unixes seem to.
  • Loading branch information
qris committed Jun 20, 2019
1 parent eead891 commit c369e04
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
11 changes: 2 additions & 9 deletions lib/win32/emu.cpp
Expand Up @@ -1130,14 +1130,9 @@ DIR *opendir(const char *name)
return NULL;
}

pDir->result.d_name = 0;
return pDir;
}

// this kinda makes it not thread friendly!
// but I don't think it needs to be.
char tempbuff[MAX_PATH];

// --------------------------------------------------------------------------
//
// Function
Expand All @@ -1162,12 +1157,10 @@ struct dirent *readdir(DIR *dp)
{
den = &dp->result;
std::wstring input(dp->info.cFileName);
memset(tempbuff, 0, sizeof(tempbuff));
memset(den->d_name, 0, sizeof(den->d_name));
WideCharToMultiByte(CP_UTF8, 0, dp->info.cFileName,
-1, &tempbuff[0], sizeof (tempbuff),
-1, den->d_name, sizeof(den->d_name),
NULL, NULL);
//den->d_name = (char *)dp->info.name;
den->d_name = &tempbuff[0];
den->win_attrs = dp->info.dwFileAttributes;
if(dp->info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/win32/emu.h
Expand Up @@ -239,7 +239,7 @@ inline int strncasecmp(const char *s1, const char *s2, size_t count)

struct dirent
{
char *d_name;
char d_name[260]; // maximum filename length
int d_type; // emulated UNIX file attributes
DWORD win_attrs; // WIN32_FIND_DATA.dwFileAttributes
};
Expand Down

0 comments on commit c369e04

Please sign in to comment.