diff options
| author | Tannin <devnull@localhost> | 2014-11-11 21:42:18 +0100 |
|---|---|---|
| committer | Tannin <devnull@localhost> | 2014-11-11 21:42:18 +0100 |
| commit | 9494938534e3dc251cd1d462bb5b40b8d98103ef (patch) | |
| tree | 6fe937eab4886dc17c7b9e7d44f7d778c27f72a8 /src/shared/util.cpp | |
| parent | 7c1273b246117740dd17fb70ad712346421224d7 (diff) | |
| parent | 9ab7bada1c81eb82d97df23da64a56a0eba0bf42 (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");
}
|
