Skip to content

fix for handling of wchars on windows in getting the directory name [blocks: #4678] #4688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/util/file_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Date: January 2012
/// \return current working directory
std::string get_current_working_directory()
{
#ifndef _WIN32
#ifndef _WIN32
errno=0;
char *wd=realpath(".", nullptr);

Expand All @@ -60,13 +60,19 @@ std::string get_current_working_directory()

std::string working_directory=wd;
free(wd);
#else
char buffer[4096];
#else
TCHAR buffer[4096];
DWORD retval=GetCurrentDirectory(4096, buffer);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking: was Visual Studio now happy with 4096 or did it still complain about a buffer overrun?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is happy with 4096, I imagine it's number of character rather than size in bytes

if(retval == 0)
throw system_exceptiont("failed to get current directory of process");

# ifdef UNICODE
std::string working_directory(narrow(buffer));
# else
std::string working_directory(buffer);
#endif
# endif

#endif

return working_directory;
}
Expand Down