diff options
| author | Tannin <devnull@localhost> | 2014-11-06 00:07:06 +0100 |
|---|---|---|
| committer | Tannin <devnull@localhost> | 2014-11-06 00:07:06 +0100 |
| commit | 10cc56608135b5ca0454b7515f6e7d90f4eb7b92 (patch) | |
| tree | 8b4f79a40ac6b4e2d0e4202b88875f44986785a8 /src/shared/util.cpp | |
| parent | 53d1f3e00e8f2cfc8f2d715b4bbbf0309dcb8947 (diff) | |
| parent | df0bd3331a4b2174f99117c5a6f21ff6bddca1ba (diff) | |
Merge
Diffstat (limited to 'src/shared/util.cpp')
| -rw-r--r-- | src/shared/util.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/shared/util.cpp b/src/shared/util.cpp index 4bc5a8a4..d4a77929 100644 --- a/src/shared/util.cpp +++ b/src/shared/util.cpp @@ -71,7 +71,9 @@ std::string ToString(const std::wstring &source, bool utf8) if (sizeRequired == 0) {
throw windows_error("failed to convert string to multibyte");
}
- result.resize(sizeRequired, '\0');
+ // the size returned by WideCharToMultiByte contains zero termination IF -1 is specified for the length.
+ // we don't want that \0 in the string because then the length field would be wrong. Because madness
+ result.resize(sizeRequired - 1, '\0');
::WideCharToMultiByte(codepage, 0, &source[0], (int)source.size(), &result[0], sizeRequired, NULL, NULL);
return result;
}
@@ -117,14 +119,15 @@ std::wstring ToLower(const std::wstring &text) VS_FIXEDFILEINFO GetFileVersion(const std::wstring &fileName)
{
- DWORD size = ::GetFileVersionInfoSizeW(fileName.c_str(), NULL);
+ DWORD handle;
+ DWORD size = ::GetFileVersionInfoSizeW(fileName.c_str(), &handle);
if (size == 0) {
throw windows_error("failed to determine file version info size");
}
void *buffer = new char[size];
try {
- if (!::GetFileVersionInfoW(fileName.c_str(), 0UL, size, buffer)) {
+ if (!::GetFileVersionInfoW(fileName.c_str(), handle, size, buffer)) {
throw windows_error("failed to determine file version info");
}
|
