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

Conversation

BrettSchiff
Copy link

directory names needed to be fetched using wchar instead of char

Copy link
Collaborator

@tautschnig tautschnig left a 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.

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());
Copy link
Collaborator

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);
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

@@ -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];
Copy link
Contributor

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.

Copy link
Collaborator

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.

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Author

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!

@tautschnig tautschnig changed the title fix for handling of wchars on windows in getting the directory name fix for handling of wchars on windows in getting the directory name [blocks: #4678] May 22, 2019
@BrettSchiff BrettSchiff force-pushed the directory_wchar_fix branch from 83d835c to 7ff0c4c Compare May 22, 2019 21:00
@tautschnig tautschnig force-pushed the directory_wchar_fix branch from 7ff0c4c to 1aa166f Compare May 23, 2019 05:26
@tautschnig tautschnig force-pushed the directory_wchar_fix branch from 1aa166f to bbbc714 Compare May 23, 2019 05:29
@tautschnig tautschnig merged commit 7b56d70 into diffblue:develop May 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants