-
Notifications
You must be signed in to change notification settings - Fork 277
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd hope that my suggestions below also address the failing CI steps.
src/util/file_util.cpp
Outdated
DWORD retval=GetCurrentDirectory(4096, buffer); | ||
if(retval == 0) | ||
throw system_exceptiont("failed to get current directory of process"); | ||
std::string working_directory(buffer); | ||
std::wstring unicode_buffer(buffer); | ||
std::string working_directory(unicode_buffer.begin(), unicode_buffer.end()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest to use std::string working_directory(narrow(buffer));
with an additional #include "unicode.h"
.
@@ -61,11 +61,12 @@ std::string get_current_working_directory() | |||
std::string working_directory=wd; | |||
free(wd); | |||
#else | |||
char buffer[4096]; | |||
wchar_t buffer[4096]; | |||
DWORD retval=GetCurrentDirectory(4096, buffer); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
src/util/file_util.cpp
Outdated
@@ -61,11 +61,12 @@ std::string get_current_working_directory() | |||
std::string working_directory=wd; | |||
free(wd); | |||
#else | |||
char buffer[4096]; | |||
wchar_t buffer[4096]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This depends on whether you compile with -DUNICODE
or not. Since this ever got committed / builds in CI in this state, it looks like some builds do not define UNICODE
. TCHAR buffer[4096]
will give a Unicode-agnostic buffer of either 8- or 16-bit chars as per configuration, and similarly some sort of #ifdef UNICODE
should be used to guard the use of wstring
below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, thank you, that explains why building via Visual Studio/msbuild yields different results than via make
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively of course we could assert that no right-minded person would ever build without -DUNICODE
any longer and do this everywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that is very useful, thank you!
83d835c
to
7ff0c4c
Compare
7ff0c4c
to
1aa166f
Compare
1aa166f
to
bbbc714
Compare
directory names needed to be fetched using wchar instead of char