Codechange: Replace all usages of alloca/AllocaM with more modern/less discouraged alternatives
This commit is contained in:
@@ -544,10 +544,9 @@ std::string FS2OTTD(const std::wstring &name)
|
||||
int name_len = (name.length() >= INT_MAX) ? INT_MAX : (int)name.length();
|
||||
int len = WideCharToMultiByte(CP_UTF8, 0, name.c_str(), name_len, nullptr, 0, nullptr, nullptr);
|
||||
if (len <= 0) return std::string();
|
||||
char *utf8_buf = AllocaM(char, len + 1);
|
||||
utf8_buf[len] = '\0';
|
||||
WideCharToMultiByte(CP_UTF8, 0, name.c_str(), name_len, utf8_buf, len, nullptr, nullptr);
|
||||
return std::string(utf8_buf, static_cast<size_t>(len));
|
||||
std::string utf8_buf(len, '\0'); // len includes terminating null
|
||||
WideCharToMultiByte(CP_UTF8, 0, name.c_str(), name_len, utf8_buf.data(), len, nullptr, nullptr);
|
||||
return utf8_buf;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -562,10 +561,9 @@ std::wstring OTTD2FS(const std::string &name)
|
||||
int name_len = (name.length() >= INT_MAX) ? INT_MAX : (int)name.length();
|
||||
int len = MultiByteToWideChar(CP_UTF8, 0, name.c_str(), name_len, nullptr, 0);
|
||||
if (len <= 0) return std::wstring();
|
||||
wchar_t *system_buf = AllocaM(wchar_t, len + 1);
|
||||
system_buf[len] = L'\0';
|
||||
MultiByteToWideChar(CP_UTF8, 0, name.c_str(), name_len, system_buf, len);
|
||||
return std::wstring(system_buf, static_cast<size_t>(len));
|
||||
std::wstring system_buf(len, L'\0'); // len includes terminating null
|
||||
MultiByteToWideChar(CP_UTF8, 0, name.c_str(), name_len, system_buf.data(), len);
|
||||
return system_buf;
|
||||
}
|
||||
|
||||
|
||||
@@ -669,13 +667,13 @@ int OTTDStringCompare(const char *s1, const char *s2)
|
||||
int len_s2 = MultiByteToWideChar(CP_UTF8, 0, s2, -1, nullptr, 0);
|
||||
|
||||
if (len_s1 != 0 && len_s2 != 0) {
|
||||
LPWSTR str_s1 = AllocaM(WCHAR, len_s1);
|
||||
LPWSTR str_s2 = AllocaM(WCHAR, len_s2);
|
||||
std::wstring str_s1(len_s1, L'\0'); // len includes terminating null
|
||||
std::wstring str_s2(len_s2, L'\0');
|
||||
|
||||
MultiByteToWideChar(CP_UTF8, 0, s1, -1, str_s1, len_s1);
|
||||
MultiByteToWideChar(CP_UTF8, 0, s2, -1, str_s2, len_s2);
|
||||
MultiByteToWideChar(CP_UTF8, 0, s1, -1, str_s1.data(), len_s1);
|
||||
MultiByteToWideChar(CP_UTF8, 0, s2, -1, str_s2.data(), len_s2);
|
||||
|
||||
int result = _CompareStringEx(_cur_iso_locale, LINGUISTIC_IGNORECASE | SORT_DIGITSASNUMBERS, str_s1, -1, str_s2, -1, nullptr, nullptr, 0);
|
||||
int result = _CompareStringEx(_cur_iso_locale, LINGUISTIC_IGNORECASE | SORT_DIGITSASNUMBERS, str_s1.c_str(), -1, str_s2.c_str(), -1, nullptr, nullptr, 0);
|
||||
if (result != 0) return result;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user