ALL: Synced with ScummVM - rev: 33a47d23b8

This commit is contained in:
Pawel Kolodziejski 2020-09-03 02:01:03 +02:00
parent acd114234f
commit d5304e2568
261 changed files with 79849 additions and 60443 deletions

View file

@ -474,18 +474,12 @@ char *OSystem_Win32::convertEncoding(const char* to, const char *from, const cha
}
memcpy(tmpStr, string, length);
} else {
// Win32::ansiToUnicode uses new to allocate the memory. We need to copy it into an array
// allocated with malloc as it is going to be freed using free.
WCHAR *tmpStr2 = Win32::ansiToUnicode(string, Win32::getCodePageId(from));
if (!tmpStr2) {
tmpStr = Win32::ansiToUnicode(string, Win32::getCodePageId(from));
if (!tmpStr) {
if (newString != nullptr)
free(newString);
return nullptr;
}
size_t size = wcslen(tmpStr2) + 1; // +1 for the terminating null wchar
tmpStr = (WCHAR *) malloc(sizeof(WCHAR) * size);
memcpy(tmpStr, tmpStr2, sizeof(WCHAR) * size);
delete[] tmpStr2;
}
if (newString != nullptr)
@ -501,15 +495,7 @@ char *OSystem_Win32::convertEncoding(const char* to, const char *from, const cha
} else {
result = Win32::unicodeToAnsi(tmpStr, Win32::getCodePageId(to));
free(tmpStr);
if (!result)
return nullptr;
// Win32::unicodeToAnsi uses new to allocate the memory. We need to copy it into an array
// allocated with malloc as it is going to be freed using free.
size_t size = strlen(result) + 1;
char *resultCopy = (char *) malloc(sizeof(char) * size);
memcpy(resultCopy, result, sizeof(char) * size);
delete[] result;
return resultCopy;
return result;
}
}