-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Fixes incorrect wide string conversion on win32 #1516
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
fb83f84
to
94ad6f6
Compare
src/sysinfo.cc
Outdated
converted.begin(), converted.size()); | ||
str.resize(len); | ||
WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, hostname, DWCOUNT, &str[0], | ||
len, NULL, NULL); | ||
// TODO: Report error from GetLastError()? | ||
if (len == 0) return std::string(""); |
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 think this check is redundant if you don't capture the returned length from the second call to WideCharToMultiByte
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.
Yeah I agree the check is redundant. Even with them functioning they still would be redundant as the documentation specifies 0
to be returned when the WideCharToMultiByte
fails so it's safe to remove them both. I kept them around for consistency reasons with the previous PR.
I've resolved this by removing both error checks, as the downstream code would be safe to execute regardless.
i can't see how this causes the issues in the asan checks, given the change is windows-only. but if you could just either check the return value of the second call or remove the redundant check, then we can get this merged :) |
Yeah, very strange asan would trigger on that, I'll need to check it out |
Yeah, honestly no clue why ASAN would trigger for code it shouldn't be concerned with to begin with. I can remove the The second call to |
I'm reluctant to merge this PR with ASAN failing. I don't really have the time to debug why that's the case. I'll be leaving this open, and hopefully someone else can come along and figure out why these Windows-only lines trip ASAN on Ubuntu. |
i'm poking at it today. |
i have convinced myself that this is an issue with the standard library rather than an issue with benchmark. in this case, we are passing in a string from the command line that is used as a regex to filter the benchmarks. asan is finding an issue where std::regex creates a std::runtime_error but deallocates a std::range_error. both of these in libc++. nothing here is related to your change so i'm happy to merge. |
Thanks for checking it out! That sounds exceptionally weird (heh). |
Fixes issue #1515 that I reported.
The PR this fixes incorrectly tried to convert an existing wide string (
GetComputerName
returns a wide string when building withUNICODE
) into another wide string (std::vector<wchar_t> converted
specifically), and then tried to simply initialize anstd::string
with awchar_t*
.I preserved the error handling from the original code (ignoring the error and just returning nothing). Depending on your affinity to exceptions, that PR originally replaced
std::wstring_convert
which would throw anstd::range_error
. I'm happy to preserve that behaviour.I locally ran this to verify the output, feel free to test this more rigorously.