mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 11:03:00 +01:00
Merge pull request #12899 from Gymnasiast/refactor/c-style-casts
Remove most remaining C-style casts
This commit is contained in:
@@ -1754,8 +1754,8 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
||||
ScreenCoordsXY screenCoords(w->windowPos.x, w->windowPos.y);
|
||||
|
||||
// Draw coordinates
|
||||
gfx_draw_string(dpi, (char*)"X:", COLOUR_WHITE, screenCoords + ScreenCoordsXY(5, 24));
|
||||
gfx_draw_string(dpi, (char*)"Y:", COLOUR_WHITE, screenCoords + ScreenCoordsXY(74, 24));
|
||||
gfx_draw_string(dpi, "X:", COLOUR_WHITE, screenCoords + ScreenCoordsXY(5, 24));
|
||||
gfx_draw_string(dpi, "Y:", COLOUR_WHITE, screenCoords + ScreenCoordsXY(74, 24));
|
||||
if (windowTileInspectorTileSelected)
|
||||
{
|
||||
auto tileCoords = TileCoordsXY{ windowTileInspectorToolMap };
|
||||
@@ -1764,8 +1764,8 @@ static void window_tile_inspector_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
||||
}
|
||||
else
|
||||
{
|
||||
gfx_draw_string(dpi, (char*)"-", COLOUR_WHITE, screenCoords + ScreenCoordsXY(43 - 7, 24));
|
||||
gfx_draw_string(dpi, (char*)"-", COLOUR_WHITE, screenCoords + ScreenCoordsXY(113, 24));
|
||||
gfx_draw_string(dpi, "-", COLOUR_WHITE, screenCoords + ScreenCoordsXY(43 - 7, 24));
|
||||
gfx_draw_string(dpi, "-", COLOUR_WHITE, screenCoords + ScreenCoordsXY(113, 24));
|
||||
}
|
||||
|
||||
if (windowTileInspectorSelectedIndex != -1)
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <windows.h>
|
||||
#include <wincrypt.h>
|
||||
#include <bcrypt.h>
|
||||
#define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0)
|
||||
constexpr bool NT_SUCCESS(NTSTATUS status) {return status >= 0;}
|
||||
// clang-format on
|
||||
|
||||
using namespace Crypt;
|
||||
@@ -85,7 +85,7 @@ public:
|
||||
|
||||
TBase* Update(const void* data, size_t dataLen) override
|
||||
{
|
||||
auto status = BCryptHashData(_hHash, (PBYTE)data, (ULONG)dataLen, 0);
|
||||
auto status = BCryptHashData(_hHash, reinterpret_cast<PBYTE>(const_cast<void*>(data)), static_cast<ULONG>(dataLen), 0);
|
||||
CngThrowOnBadStatus("BCryptHashData", status);
|
||||
return this;
|
||||
}
|
||||
@@ -93,7 +93,7 @@ public:
|
||||
typename TBase::Result Finish() override
|
||||
{
|
||||
typename TBase::Result result;
|
||||
auto status = BCryptFinishHash(_hHash, result.data(), (ULONG)result.size(), 0);
|
||||
auto status = BCryptFinishHash(_hHash, result.data(), static_cast<ULONG>(result.size()), 0);
|
||||
CngThrowOnBadStatus("BCryptFinishHash", status);
|
||||
return result;
|
||||
}
|
||||
@@ -108,11 +108,12 @@ private:
|
||||
// Calculate the size of the buffer to hold the hash object
|
||||
DWORD cbHashObject{};
|
||||
DWORD cbData{};
|
||||
status = BCryptGetProperty(_hAlg, BCRYPT_OBJECT_LENGTH, (PBYTE)&cbHashObject, sizeof(DWORD), &cbData, 0);
|
||||
status = BCryptGetProperty(
|
||||
_hAlg, BCRYPT_OBJECT_LENGTH, reinterpret_cast<PBYTE>(&cbHashObject), sizeof(DWORD), &cbData, 0);
|
||||
CngThrowOnBadStatus("BCryptGetProperty", status);
|
||||
|
||||
// Create a hash
|
||||
_pbHashObject = (PBYTE)HeapAlloc(GetProcessHeap(), 0, cbHashObject);
|
||||
_pbHashObject = reinterpret_cast<PBYTE>(HeapAlloc(GetProcessHeap(), 0, cbHashObject));
|
||||
ThrowBadAllocOnNull(_pbHashObject);
|
||||
status = BCryptCreateHash(_hAlg, &_hHash, _pbHashObject, cbHashObject, nullptr, 0, 0);
|
||||
CngThrowOnBadStatus("BCryptCreateHash", status);
|
||||
@@ -138,14 +139,14 @@ private:
|
||||
template<typename T> T Read(std::istream& stream)
|
||||
{
|
||||
T value;
|
||||
stream.read((char*)&value, sizeof(T));
|
||||
stream.read(reinterpret_cast<char*>(&value), sizeof(T));
|
||||
return value;
|
||||
}
|
||||
|
||||
template<typename T> std::vector<T> Read(std::istream& stream, size_t count)
|
||||
{
|
||||
std::vector<T> values(count);
|
||||
stream.read((char*)values.data(), sizeof(T) * count);
|
||||
stream.read(reinterpret_cast<char*>(values.data()), sizeof(T) * count);
|
||||
return values;
|
||||
}
|
||||
|
||||
@@ -324,7 +325,7 @@ private:
|
||||
static RsaKeyParams FromBlob(const std::vector<uint8_t>& blob)
|
||||
{
|
||||
RsaKeyParams result;
|
||||
const auto& header = *((BCRYPT_RSAKEY_BLOB*)blob.data());
|
||||
const auto& header = *(reinterpret_cast<const BCRYPT_RSAKEY_BLOB*>(blob.data()));
|
||||
size_t offset = sizeof(BCRYPT_RSAKEY_BLOB);
|
||||
result.Exponent = ReadBytes(blob, offset, header.cbPublicExp);
|
||||
result.Modulus = ReadBytes(blob, offset, header.cbModulus);
|
||||
@@ -347,13 +348,13 @@ private:
|
||||
{
|
||||
auto magic = GetMagic();
|
||||
std::vector<uint8_t> blob(sizeof(BCRYPT_RSAKEY_BLOB));
|
||||
auto& header = *((BCRYPT_RSAKEY_BLOB*)blob.data());
|
||||
auto& header = *(reinterpret_cast<BCRYPT_RSAKEY_BLOB*>(blob.data()));
|
||||
header.Magic = magic;
|
||||
header.BitLength = (ULONG)(Modulus.size() * 8);
|
||||
header.cbPublicExp = (ULONG)Exponent.size();
|
||||
header.cbModulus = (ULONG)Modulus.size();
|
||||
header.cbPrime1 = (ULONG)Prime1.size();
|
||||
header.cbPrime2 = (ULONG)Prime2.size();
|
||||
header.BitLength = static_cast<ULONG>(Modulus.size() * 8);
|
||||
header.cbPublicExp = static_cast<ULONG>(Exponent.size());
|
||||
header.cbModulus = static_cast<ULONG>(Modulus.size());
|
||||
header.cbPrime1 = static_cast<ULONG>(Prime1.size());
|
||||
header.cbPrime2 = static_cast<ULONG>(Prime2.size());
|
||||
|
||||
WriteBytes(blob, Exponent);
|
||||
WriteBytes(blob, Modulus);
|
||||
@@ -515,7 +516,7 @@ private:
|
||||
Reset();
|
||||
auto blob = params.ToBlob();
|
||||
_keyBlobType = params.GetMagic() == BCRYPT_RSAFULLPRIVATE_MAGIC ? BCRYPT_RSAFULLPRIVATE_BLOB : BCRYPT_RSAPUBLIC_BLOB;
|
||||
auto status = BCryptImportKeyPair(_hAlg, NULL, _keyBlobType, &_hKey, blob.data(), (ULONG)blob.size(), 0);
|
||||
auto status = BCryptImportKeyPair(_hAlg, NULL, _keyBlobType, &_hKey, blob.data(), static_cast<ULONG>(blob.size()), 0);
|
||||
CngThrowOnBadStatus("BCryptImportKeyPair", status);
|
||||
}
|
||||
|
||||
@@ -569,12 +570,12 @@ private:
|
||||
{
|
||||
DWORD flags = CRYPT_STRING_BASE64 | CRYPT_STRING_NOCR;
|
||||
DWORD chString{};
|
||||
if (!CryptBinaryToStringA(input.data(), (DWORD)input.size(), flags, NULL, &chString))
|
||||
if (!CryptBinaryToStringA(input.data(), static_cast<DWORD>(input.size()), flags, NULL, &chString))
|
||||
{
|
||||
throw std::runtime_error("CryptBinaryToStringA failed");
|
||||
}
|
||||
std::string result(chString, 0);
|
||||
if (!CryptBinaryToStringA(input.data(), (DWORD)input.size(), flags, result.data(), &chString))
|
||||
if (!CryptBinaryToStringA(input.data(), static_cast<DWORD>(input.size()), flags, result.data(), &chString))
|
||||
{
|
||||
throw std::runtime_error("CryptBinaryToStringA failed");
|
||||
}
|
||||
@@ -588,12 +589,14 @@ private:
|
||||
static std::vector<uint8_t> DecodeBase64(const std::string_view& input)
|
||||
{
|
||||
DWORD cbBinary{};
|
||||
if (!CryptStringToBinaryA(input.data(), (DWORD)input.size(), CRYPT_STRING_BASE64, NULL, &cbBinary, NULL, NULL))
|
||||
if (!CryptStringToBinaryA(
|
||||
input.data(), static_cast<DWORD>(input.size()), CRYPT_STRING_BASE64, NULL, &cbBinary, NULL, NULL))
|
||||
{
|
||||
throw std::runtime_error("CryptStringToBinaryA failed");
|
||||
}
|
||||
std::vector<uint8_t> result(cbBinary);
|
||||
if (!CryptStringToBinaryA(input.data(), (DWORD)input.size(), CRYPT_STRING_BASE64, result.data(), &cbBinary, NULL, NULL))
|
||||
if (!CryptStringToBinaryA(
|
||||
input.data(), static_cast<DWORD>(input.size()), CRYPT_STRING_BASE64, result.data(), &cbBinary, NULL, NULL))
|
||||
{
|
||||
throw std::runtime_error("CryptStringToBinaryA failed");
|
||||
}
|
||||
@@ -614,7 +617,7 @@ public:
|
||||
BCRYPT_PKCS1_PADDING_INFO paddingInfo{ BCRYPT_SHA256_ALGORITHM };
|
||||
auto status = BCryptSignHash(hKey, &paddingInfo, pbHash, cbHash, NULL, 0, &cbSignature, BCRYPT_PAD_PKCS1);
|
||||
CngThrowOnBadStatus("BCryptSignHash", status);
|
||||
pbSignature = (PBYTE)HeapAlloc(GetProcessHeap(), 0, cbSignature);
|
||||
pbSignature = reinterpret_cast<PBYTE>(HeapAlloc(GetProcessHeap(), 0, cbSignature));
|
||||
ThrowBadAllocOnNull(pbSignature);
|
||||
status = BCryptSignHash(
|
||||
hKey, &paddingInfo, pbHash, cbHash, pbSignature, cbSignature, &cbSignature, BCRYPT_PAD_PKCS1);
|
||||
@@ -653,8 +656,8 @@ private:
|
||||
|
||||
static std::tuple<DWORD, PBYTE> ToHeap(const void* data, size_t dataLen)
|
||||
{
|
||||
auto cbHash = (DWORD)dataLen;
|
||||
auto pbHash = (PBYTE)HeapAlloc(GetProcessHeap(), 0, dataLen);
|
||||
auto cbHash = static_cast<DWORD>(dataLen);
|
||||
auto pbHash = reinterpret_cast<PBYTE>(HeapAlloc(GetProcessHeap(), 0, dataLen));
|
||||
ThrowBadAllocOnNull(pbHash);
|
||||
std::memcpy(pbHash, data, dataLen);
|
||||
return std::make_tuple(cbHash, pbHash);
|
||||
|
||||
@@ -131,7 +131,8 @@ namespace File
|
||||
FILETIME ftCreate, ftAccess, ftWrite;
|
||||
if (GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite))
|
||||
{
|
||||
lastModified = ((uint64_t)ftWrite.dwHighDateTime << 32ULL) | (uint64_t)ftWrite.dwLowDateTime;
|
||||
lastModified = (static_cast<uint64_t>(ftWrite.dwHighDateTime) << 32ULL)
|
||||
| static_cast<uint64_t>(ftWrite.dwLowDateTime);
|
||||
}
|
||||
CloseHandle(hFile);
|
||||
}
|
||||
|
||||
@@ -258,9 +258,9 @@ private:
|
||||
else
|
||||
{
|
||||
result.Type = DIRECTORY_CHILD_TYPE::DC_FILE;
|
||||
result.Size = ((uint64_t)child->nFileSizeHigh << 32ULL) | (uint64_t)child->nFileSizeLow;
|
||||
result.LastModified = ((uint64_t)child->ftLastWriteTime.dwHighDateTime << 32ULL)
|
||||
| (uint64_t)child->ftLastWriteTime.dwLowDateTime;
|
||||
result.Size = (static_cast<uint64_t>(child->nFileSizeHigh) << 32ULL) | static_cast<uint64_t>(child->nFileSizeLow);
|
||||
result.LastModified = (static_cast<uint64_t>(child->ftLastWriteTime.dwHighDateTime) << 32ULL)
|
||||
| static_cast<uint64_t>(child->ftLastWriteTime.dwLowDateTime);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -134,8 +134,8 @@ void FileWatcher::WatchDirectory()
|
||||
std::array<char, 1024> eventData;
|
||||
DWORD bytesReturned;
|
||||
while (ReadDirectoryChangesW(
|
||||
_directoryHandle, eventData.data(), (DWORD)eventData.size(), TRUE, FILE_NOTIFY_CHANGE_LAST_WRITE, &bytesReturned,
|
||||
nullptr, nullptr))
|
||||
_directoryHandle, eventData.data(), static_cast<DWORD>(eventData.size()), TRUE, FILE_NOTIFY_CHANGE_LAST_WRITE,
|
||||
&bytesReturned, nullptr, nullptr))
|
||||
{
|
||||
auto onFileChanged = OnFileChanged;
|
||||
if (onFileChanged)
|
||||
@@ -144,7 +144,7 @@ void FileWatcher::WatchDirectory()
|
||||
size_t offset = 0;
|
||||
do
|
||||
{
|
||||
notifyInfo = (FILE_NOTIFY_INFORMATION*)(eventData.data() + offset);
|
||||
notifyInfo = reinterpret_cast<FILE_NOTIFY_INFORMATION*>(eventData.data() + offset);
|
||||
offset += notifyInfo->NextEntryOffset;
|
||||
|
||||
std::wstring fileNameW(notifyInfo->FileName, notifyInfo->FileNameLength / sizeof(wchar_t));
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace Http
|
||||
static int32_t ReadStatusCode(HINTERNET hRequest)
|
||||
{
|
||||
wchar_t headerBuffer[32]{};
|
||||
auto headerBufferLen = (DWORD)std::size(headerBuffer);
|
||||
auto headerBufferLen = static_cast<DWORD>(std::size(headerBuffer));
|
||||
if (!WinHttpQueryHeaders(
|
||||
hRequest, WINHTTP_QUERY_STATUS_CODE, L"StatusCode", headerBuffer, &headerBufferLen, WINHTTP_NO_HEADER_INDEX))
|
||||
{
|
||||
@@ -136,7 +136,7 @@ namespace Http
|
||||
dwSizeToRead = 4096;
|
||||
|
||||
body.resize(dwRealSize + dwSizeToRead);
|
||||
auto dst = (LPVOID)&body[dwRealSize];
|
||||
auto dst = reinterpret_cast<LPVOID>(&body[dwRealSize]);
|
||||
|
||||
dwDownloaded = 0;
|
||||
if (!WinHttpReadData(hRequest, dst, dwSizeToRead, &dwDownloaded))
|
||||
@@ -156,10 +156,10 @@ namespace Http
|
||||
{
|
||||
URL_COMPONENTS url{};
|
||||
url.dwStructSize = sizeof(url);
|
||||
url.dwSchemeLength = (DWORD)-1;
|
||||
url.dwHostNameLength = (DWORD)-1;
|
||||
url.dwUrlPathLength = (DWORD)-1;
|
||||
url.dwExtraInfoLength = (DWORD)-1;
|
||||
url.dwSchemeLength = static_cast<DWORD>(-1);
|
||||
url.dwHostNameLength = static_cast<DWORD>(-1);
|
||||
url.dwUrlPathLength = static_cast<DWORD>(-1);
|
||||
url.dwExtraInfoLength = static_cast<DWORD>(-1);
|
||||
|
||||
auto wUrl = String::ToWideChar(req.url);
|
||||
if (!WinHttpCrackUrl(wUrl.c_str(), 0, 0, &url))
|
||||
@@ -192,12 +192,12 @@ namespace Http
|
||||
for (auto header : req.header)
|
||||
{
|
||||
auto fullHeader = String::ToWideChar(header.first) + L": " + String::ToWideChar(header.second);
|
||||
if (!WinHttpAddRequestHeaders(hRequest, fullHeader.c_str(), (ULONG)-1L, WINHTTP_ADDREQ_FLAG_ADD))
|
||||
if (!WinHttpAddRequestHeaders(hRequest, fullHeader.c_str(), static_cast<ULONG>(-1L), WINHTTP_ADDREQ_FLAG_ADD))
|
||||
ThrowWin32Exception("WinHttpAddRequestHeaders");
|
||||
}
|
||||
|
||||
auto reqBody = (LPVOID)req.body.data();
|
||||
auto reqBodyLen = (DWORD)req.body.size();
|
||||
auto reqBody = reinterpret_cast<LPVOID>(const_cast<char*>(req.body.data()));
|
||||
auto reqBodyLen = static_cast<DWORD>(req.body.size());
|
||||
if (!WinHttpSendRequest(hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, reqBody, reqBodyLen, reqBodyLen, 0))
|
||||
ThrowWin32Exception("WinHttpSendRequest");
|
||||
|
||||
@@ -210,7 +210,7 @@ namespace Http
|
||||
|
||||
Response response;
|
||||
response.body = std::move(body);
|
||||
response.status = (Status)statusCode;
|
||||
response.status = static_cast<Status>(statusCode);
|
||||
auto it = headers.find("Content-Type");
|
||||
if (it != headers.end())
|
||||
{
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace Memory
|
||||
|
||||
template<typename T> static void Free(T* ptr)
|
||||
{
|
||||
free((void*)ptr);
|
||||
free(const_cast<void*>(reinterpret_cast<const void*>(ptr)));
|
||||
}
|
||||
|
||||
template<typename T> static void FreeArray(T* ptr, size_t count)
|
||||
|
||||
@@ -174,7 +174,8 @@ namespace Path
|
||||
#ifdef _WIN32
|
||||
auto relativePathW = String::ToWideChar(relativePath);
|
||||
wchar_t absolutePathW[MAX_PATH];
|
||||
DWORD length = GetFullPathNameW(relativePathW.c_str(), (DWORD)std::size(absolutePathW), absolutePathW, nullptr);
|
||||
DWORD length = GetFullPathNameW(
|
||||
relativePathW.c_str(), static_cast<DWORD>(std::size(absolutePathW)), absolutePathW, nullptr);
|
||||
if (length == 0)
|
||||
{
|
||||
return String::Set(buffer, bufferSize, relativePath);
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace String
|
||||
std::string ToUtf8(const std::wstring_view& src)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
int srcLen = (int)src.size();
|
||||
int srcLen = static_cast<int>(src.size());
|
||||
int sizeReq = WideCharToMultiByte(CODE_PAGE::CP_UTF8, 0, src.data(), srcLen, nullptr, 0, nullptr, nullptr);
|
||||
auto result = std::string(sizeReq, 0);
|
||||
WideCharToMultiByte(CODE_PAGE::CP_UTF8, 0, src.data(), srcLen, result.data(), sizeReq, nullptr, nullptr);
|
||||
@@ -96,7 +96,7 @@ namespace String
|
||||
std::wstring ToWideChar(const std::string_view& src)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
int srcLen = (int)src.size();
|
||||
int srcLen = static_cast<int>(src.size());
|
||||
int sizeReq = MultiByteToWideChar(CODE_PAGE::CP_UTF8, 0, src.data(), srcLen, nullptr, 0);
|
||||
auto result = std::wstring(sizeReq, 0);
|
||||
MultiByteToWideChar(CODE_PAGE::CP_UTF8, 0, src.data(), srcLen, result.data(), sizeReq);
|
||||
@@ -667,7 +667,7 @@ namespace String
|
||||
// Convert from source code page to UTF-16
|
||||
std::wstring u16;
|
||||
{
|
||||
int srcLen = (int)src.size();
|
||||
int srcLen = static_cast<int>(src.size());
|
||||
int sizeReq = MultiByteToWideChar(srcCodePage, 0, src.data(), srcLen, nullptr, 0);
|
||||
u16 = std::wstring(sizeReq, 0);
|
||||
MultiByteToWideChar(srcCodePage, 0, src.data(), srcLen, u16.data(), sizeReq);
|
||||
@@ -676,7 +676,7 @@ namespace String
|
||||
// Convert from UTF-16 to destination code page
|
||||
std::string dst;
|
||||
{
|
||||
int srcLen = (int)u16.size();
|
||||
int srcLen = static_cast<int>(u16.size());
|
||||
int sizeReq = WideCharToMultiByte(dstCodePage, 0, u16.data(), srcLen, nullptr, 0, nullptr, nullptr);
|
||||
dst = std::string(sizeReq, 0);
|
||||
WideCharToMultiByte(dstCodePage, 0, u16.data(), srcLen, dst.data(), sizeReq, nullptr, nullptr);
|
||||
@@ -709,16 +709,16 @@ namespace String
|
||||
|
||||
// Measure how long the destination needs to be
|
||||
auto requiredSize = LCMapStringEx(
|
||||
LOCALE_NAME_USER_DEFAULT, LCMAP_UPPERCASE | LCMAP_LINGUISTIC_CASING, srcW.c_str(), (int)srcW.length(), nullptr, 0,
|
||||
nullptr, nullptr, 0);
|
||||
LOCALE_NAME_USER_DEFAULT, LCMAP_UPPERCASE | LCMAP_LINGUISTIC_CASING, srcW.c_str(), static_cast<int>(srcW.length()),
|
||||
nullptr, 0, nullptr, nullptr, 0);
|
||||
|
||||
auto dstW = std::wstring();
|
||||
dstW.resize(requiredSize);
|
||||
|
||||
// Transform the string
|
||||
auto result = LCMapStringEx(
|
||||
LOCALE_NAME_USER_DEFAULT, LCMAP_UPPERCASE | LCMAP_LINGUISTIC_CASING, srcW.c_str(), (int)srcW.length(), dstW.data(),
|
||||
(int)dstW.length(), nullptr, nullptr, 0);
|
||||
LOCALE_NAME_USER_DEFAULT, LCMAP_UPPERCASE | LCMAP_LINGUISTIC_CASING, srcW.c_str(), static_cast<int>(srcW.length()),
|
||||
dstW.data(), static_cast<int>(dstW.length()), nullptr, nullptr, 0);
|
||||
if (result == 0)
|
||||
{
|
||||
// Check the error
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
// Adapted from freetype.h in order to avoid C-style casts.
|
||||
|
||||
#define FT_LOAD_TARGET_ALT(x) (static_cast<FT_Int32>((x)&15) << 16)
|
||||
#define FT_IMAGE_TAG(value, _x1, _x2, _x3, _x4) \
|
||||
value \
|
||||
= ((static_cast<unsigned long>(_x1) << 24) | (static_cast<unsigned long>(_x2) << 16) \
|
||||
| (static_cast<unsigned long>(_x3) << 8) | static_cast<unsigned long>(_x4))
|
||||
|
||||
/**
|
||||
* The following code is from SDL2_ttf (2 Jan 2017).
|
||||
|
||||
@@ -915,8 +915,8 @@ static std::vector<INTERFACE_INFO> GetNetworkInterfaces()
|
||||
{
|
||||
interfaces.resize(capacity);
|
||||
if (WSAIoctl(
|
||||
sock, SIO_GET_INTERFACE_LIST, nullptr, 0, interfaces.data(), (DWORD)(capacity * sizeof(INTERFACE_INFO)), &len,
|
||||
nullptr, nullptr)
|
||||
sock, SIO_GET_INTERFACE_LIST, nullptr, 0, interfaces.data(),
|
||||
static_cast<DWORD>(capacity * sizeof(INTERFACE_INFO)), &len, nullptr, nullptr)
|
||||
== 0)
|
||||
{
|
||||
break;
|
||||
@@ -949,9 +949,10 @@ std::vector<std::unique_ptr<INetworkEndpoint>> GetBroadcastAddresses()
|
||||
// iiBroadcast is unusable, because it always seems to be set to 255.255.255.255.
|
||||
sockaddr_storage address{};
|
||||
memcpy(&address, &ifo.iiAddress.Address, sizeof(sockaddr));
|
||||
((sockaddr_in*)&address)->sin_addr.s_addr = ifo.iiAddress.AddressIn.sin_addr.s_addr
|
||||
(reinterpret_cast<sockaddr_in*>(&address))->sin_addr.s_addr = ifo.iiAddress.AddressIn.sin_addr.s_addr
|
||||
| ~ifo.iiNetmask.AddressIn.sin_addr.s_addr;
|
||||
baddresses.push_back(std::make_unique<NetworkEndpoint>((const sockaddr*)&address, (socklen_t)sizeof(sockaddr)));
|
||||
baddresses.push_back(std::make_unique<NetworkEndpoint>(
|
||||
reinterpret_cast<const sockaddr*>(&address), static_cast<socklen_t>(sizeof(sockaddr))));
|
||||
}
|
||||
# else
|
||||
int sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace Platform
|
||||
std::wstring result;
|
||||
auto wname = String::ToWideChar(name);
|
||||
wchar_t wvalue[256];
|
||||
auto valueSize = GetEnvironmentVariableW(wname.c_str(), wvalue, (DWORD)std::size(wvalue));
|
||||
auto valueSize = GetEnvironmentVariableW(wname.c_str(), wvalue, static_cast<DWORD>(std::size(wvalue)));
|
||||
if (valueSize < std::size(wvalue))
|
||||
{
|
||||
result = wvalue;
|
||||
@@ -181,7 +181,7 @@ namespace Platform
|
||||
LONGLONG ll = Int32x32To64(timestamp, 10000000) + 116444736000000000;
|
||||
|
||||
FILETIME ft;
|
||||
ft.dwLowDateTime = (DWORD)ll;
|
||||
ft.dwLowDateTime = static_cast<DWORD>(ll);
|
||||
ft.dwHighDateTime = ll >> 32;
|
||||
|
||||
SYSTEMTIME st;
|
||||
@@ -234,7 +234,7 @@ namespace Platform
|
||||
# pragma GCC diagnostic push
|
||||
# pragma GCC diagnostic ignored "-Wcast-function-type"
|
||||
# endif
|
||||
auto fn = (RtlGetVersionPtr)GetProcAddress(hModule, "RtlGetVersion");
|
||||
auto fn = reinterpret_cast<RtlGetVersionPtr>(GetProcAddress(hModule, "RtlGetVersion"));
|
||||
# if defined(__GNUC__) && __GNUC__ >= 8
|
||||
# pragma GCC diagnostic pop
|
||||
# endif
|
||||
|
||||
@@ -48,14 +48,14 @@ static mach_timebase_info_data_t _mach_base_info = {};
|
||||
char* strndup(const char* src, size_t size)
|
||||
{
|
||||
size_t len = strnlen(src, size);
|
||||
char* dst = (char*)malloc(len + 1);
|
||||
char* dst = reinterpret_cast<char*>(malloc(len + 1));
|
||||
|
||||
if (dst == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
dst = (char*)std::memcpy(dst, src, len);
|
||||
dst = reinterpret_cast<char*>(std::memcpy(dst, src, len));
|
||||
dst[len] = '\0';
|
||||
return dst;
|
||||
}
|
||||
|
||||
@@ -172,8 +172,8 @@ bool platform_get_steam_path(utf8* outPath, size_t outSize)
|
||||
return false;
|
||||
}
|
||||
|
||||
wSteamPath = (wchar_t*)malloc(size);
|
||||
result = RegQueryValueExW(hKey, L"SteamPath", nullptr, &type, (LPBYTE)wSteamPath, &size);
|
||||
wSteamPath = reinterpret_cast<wchar_t*>(malloc(size));
|
||||
result = RegQueryValueExW(hKey, L"SteamPath", nullptr, &type, reinterpret_cast<LPBYTE>(wSteamPath), &size);
|
||||
if (result == ERROR_SUCCESS)
|
||||
{
|
||||
auto utf8SteamPath = String::ToUtf8(wSteamPath);
|
||||
@@ -213,7 +213,7 @@ uint16_t platform_get_locale_language()
|
||||
{
|
||||
CHAR langCode[4];
|
||||
|
||||
if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, (LPSTR)&langCode, sizeof(langCode)) == 0)
|
||||
if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, reinterpret_cast<LPSTR>(&langCode), sizeof(langCode)) == 0)
|
||||
{
|
||||
return LANGUAGE_UNDEFINED;
|
||||
}
|
||||
@@ -300,7 +300,7 @@ time_t platform_file_get_modified_time(const utf8* path)
|
||||
uint8_t platform_get_locale_currency()
|
||||
{
|
||||
CHAR currCode[4];
|
||||
if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SINTLSYMBOL, (LPSTR)&currCode, sizeof(currCode)) == 0)
|
||||
if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SINTLSYMBOL, reinterpret_cast<LPSTR>(&currCode), sizeof(currCode)) == 0)
|
||||
{
|
||||
return platform_get_currency_value(nullptr);
|
||||
}
|
||||
@@ -312,7 +312,8 @@ MeasurementFormat platform_get_locale_measurement_format()
|
||||
{
|
||||
UINT measurement_system;
|
||||
if (GetLocaleInfo(
|
||||
LOCALE_USER_DEFAULT, LOCALE_IMEASURE | LOCALE_RETURN_NUMBER, (LPSTR)&measurement_system, sizeof(measurement_system))
|
||||
LOCALE_USER_DEFAULT, LOCALE_IMEASURE | LOCALE_RETURN_NUMBER, reinterpret_cast<LPSTR>(&measurement_system),
|
||||
sizeof(measurement_system))
|
||||
== 0)
|
||||
{
|
||||
return MeasurementFormat::Metric;
|
||||
@@ -334,7 +335,10 @@ TemperatureUnit platform_get_locale_temperature_format()
|
||||
|
||||
// GetLocaleInfo will set fahrenheit to 1 if the locale on this computer
|
||||
// uses the United States measurement system or 0 otherwise.
|
||||
if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IMEASURE | LOCALE_RETURN_NUMBER, (LPSTR)&fahrenheit, sizeof(fahrenheit)) == 0)
|
||||
if (GetLocaleInfo(
|
||||
LOCALE_USER_DEFAULT, LOCALE_IMEASURE | LOCALE_RETURN_NUMBER, reinterpret_cast<LPSTR>(&fahrenheit),
|
||||
sizeof(fahrenheit))
|
||||
== 0)
|
||||
{
|
||||
// Assume celsius by default if function call fails
|
||||
return TemperatureUnit::Celsius;
|
||||
@@ -351,7 +355,7 @@ uint8_t platform_get_locale_date_format()
|
||||
# if _WIN32_WINNT >= 0x0600
|
||||
// Retrieve short date format, eg "MM/dd/yyyy"
|
||||
wchar_t dateFormat[20];
|
||||
if (GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_SSHORTDATE, dateFormat, (int)std::size(dateFormat)) == 0)
|
||||
if (GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_SSHORTDATE, dateFormat, static_cast<int>(std::size(dateFormat))) == 0)
|
||||
{
|
||||
return DATE_FORMAT_DAY_MONTH_YEAR;
|
||||
}
|
||||
@@ -446,7 +450,8 @@ std::string platform_get_absolute_path(const utf8* relativePath, const utf8* bas
|
||||
|
||||
auto pathToResolveW = String::ToWideChar(pathToResolve);
|
||||
wchar_t fullPathW[MAX_PATH]{};
|
||||
auto fullPathLen = GetFullPathNameW(pathToResolveW.c_str(), (DWORD)std::size(fullPathW), fullPathW, nullptr);
|
||||
auto fullPathLen = GetFullPathNameW(
|
||||
pathToResolveW.c_str(), static_cast<DWORD>(std::size(fullPathW)), fullPathW, nullptr);
|
||||
if (fullPathLen != 0)
|
||||
{
|
||||
result = String::ToUtf8(fullPathW);
|
||||
@@ -460,7 +465,8 @@ datetime64 platform_get_datetime_now_utc()
|
||||
// Get file time
|
||||
FILETIME fileTime;
|
||||
GetSystemTimeAsFileTime(&fileTime);
|
||||
uint64_t fileTime64 = ((uint64_t)fileTime.dwHighDateTime << 32ULL) | ((uint64_t)fileTime.dwLowDateTime);
|
||||
uint64_t fileTime64 = (static_cast<uint64_t>(fileTime.dwHighDateTime) << 32ULL)
|
||||
| (static_cast<uint64_t>(fileTime.dwLowDateTime));
|
||||
|
||||
// File time starts from: 1601-01-01T00:00:00Z
|
||||
// Convert to start from: 0001-01-01T00:00:00Z
|
||||
|
||||
@@ -369,7 +369,7 @@ ScriptEngine::ScriptEngine(InteractiveConsole& console, IPlatformEnvironment& en
|
||||
|
||||
void ScriptEngine::Initialise()
|
||||
{
|
||||
auto ctx = (duk_context*)_context;
|
||||
auto ctx = static_cast<duk_context*>(_context);
|
||||
ScCheats::Register(ctx);
|
||||
ScConfiguration::Register(ctx);
|
||||
ScConsole::Register(ctx);
|
||||
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
uint32_t hash = 27;
|
||||
for (size_t i = 0; i < bufferLength; i++)
|
||||
{
|
||||
hash = (13 * hash) + ((uint8_t*)buffer)[i];
|
||||
hash = (13 * hash) + (reinterpret_cast<uint8_t*>(buffer))[i];
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ TEST_F(IniWriterTest, create_one_section)
|
||||
ASSERT_LE(ms.GetPosition(), 13); // Accommodate for varying-sized newline (Windows)
|
||||
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
|
||||
ms.SetPosition(0);
|
||||
const char* ini = (const char*)ms.ReadString();
|
||||
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
|
||||
ASSERT_STREQ(ini, "[OpenRCT2]" PLATFORM_NEWLINE);
|
||||
Memory::Free(ini);
|
||||
delete iw;
|
||||
@@ -67,7 +67,7 @@ TEST_F(IniWriterTest, create_multiple_sections)
|
||||
ASSERT_LE(ms.GetPosition(), 55); // Accommodate for varying-sized newline (Windows)
|
||||
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
|
||||
ms.SetPosition(0);
|
||||
const char* ini = (const char*)ms.ReadString();
|
||||
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
|
||||
ASSERT_STREQ(
|
||||
ini,
|
||||
"[OpenRCT1]" PLATFORM_NEWLINE PLATFORM_NEWLINE "[OpenRCT2]" PLATFORM_NEWLINE PLATFORM_NEWLINE
|
||||
@@ -88,7 +88,7 @@ TEST_F(IniWriterTest, create_loose_bool_entry)
|
||||
ASSERT_LE(ms.GetPosition(), 17); // Accommodate for varying-sized newline (Windows)
|
||||
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
|
||||
ms.SetPosition(0);
|
||||
const char* ini = (const char*)ms.ReadString();
|
||||
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
|
||||
ASSERT_STREQ(ini, "boolval = true" PLATFORM_NEWLINE);
|
||||
Memory::Free(ini);
|
||||
delete iw;
|
||||
@@ -107,7 +107,7 @@ TEST_F(IniWriterTest, create_loose_enum_entry)
|
||||
ASSERT_LE(ms.GetPosition(), 37); // Accommodate for varying-sized newline (Windows)
|
||||
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
|
||||
ms.SetPosition(0);
|
||||
const char* ini = (const char*)ms.ReadString();
|
||||
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
|
||||
ASSERT_STREQ(ini, "by_string = stringval" PLATFORM_NEWLINE "int32_t = 0" PLATFORM_NEWLINE);
|
||||
Memory::Free(ini);
|
||||
delete iw;
|
||||
@@ -125,7 +125,7 @@ TEST_F(IniWriterTest, create_loose_float_entry)
|
||||
ASSERT_LE(ms.GetPosition(), 17); // Accommodate for varying-sized newline (Windows)
|
||||
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
|
||||
ms.SetPosition(0);
|
||||
const char* ini = (const char*)ms.ReadString();
|
||||
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
|
||||
// This will be non-fatal due to float.
|
||||
EXPECT_STREQ(ini, "one = 1.000000" PLATFORM_NEWLINE);
|
||||
Memory::Free(ini);
|
||||
@@ -148,7 +148,7 @@ TEST_F(IniWriterTest, create_loose_int32_t_entry)
|
||||
ASSERT_LE(ms.GetPosition(), 78); // Accommodate for varying-sized newline (Windows)
|
||||
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
|
||||
ms.SetPosition(0);
|
||||
const char* ini = (const char*)ms.ReadString();
|
||||
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
|
||||
ASSERT_STREQ(
|
||||
ini,
|
||||
"one = 1" PLATFORM_NEWLINE "zero = 0" PLATFORM_NEWLINE "minusone = -1" PLATFORM_NEWLINE
|
||||
@@ -169,7 +169,7 @@ TEST_F(IniWriterTest, create_loose_string_entry)
|
||||
ASSERT_LE(ms.GetPosition(), 44); // Accommodate for varying-sized newline (Windows)
|
||||
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
|
||||
ms.SetPosition(0);
|
||||
const char* ini = (const char*)ms.ReadString();
|
||||
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
|
||||
ASSERT_STREQ(ini, "path = \"C:'\\\\some/dir\\\\here/\xE7\xA5\x9E\xE9\xB7\xB9\xE6\x9A\xA2\xE9\x81\x8A\"" PLATFORM_NEWLINE);
|
||||
Memory::Free(ini);
|
||||
delete iw;
|
||||
@@ -193,7 +193,7 @@ TEST_F(IniWriterTest, create_multiple_section_with_values)
|
||||
ASSERT_LE(ms.GetPosition(), 108); // Accommodate for varying-sized newline (Windows)
|
||||
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
|
||||
ms.SetPosition(0);
|
||||
const char* ini = (const char*)ms.ReadString();
|
||||
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
|
||||
ASSERT_STREQ(
|
||||
ini,
|
||||
"[bool]" PLATFORM_NEWLINE "boolval = true" PLATFORM_NEWLINE PLATFORM_NEWLINE "[int]" PLATFORM_NEWLINE
|
||||
@@ -217,7 +217,7 @@ TEST_F(IniWriterTest, create_duplicate_sections)
|
||||
ASSERT_LE(ms.GetPosition(), 43); // Accommodate for varying-sized newline (Windows)
|
||||
ASSERT_EQ(ms.GetLength(), ms.GetPosition());
|
||||
ms.SetPosition(0);
|
||||
const char* ini = (const char*)ms.ReadString();
|
||||
const char* ini = reinterpret_cast<const char*>(ms.ReadString());
|
||||
ASSERT_STREQ(
|
||||
ini,
|
||||
"[section]" PLATFORM_NEWLINE PLATFORM_NEWLINE "[section]" PLATFORM_NEWLINE PLATFORM_NEWLINE
|
||||
|
||||
@@ -48,8 +48,8 @@ protected:
|
||||
{
|
||||
RatingTuple ratings = ride.ratings;
|
||||
std::string line = String::StdFormat(
|
||||
"%s: (%d, %d, %d)", RideTypeDescriptors[ride.type].EnumName, (int)ratings.Excitement, (int)ratings.Intensity,
|
||||
(int)ratings.Nausea);
|
||||
"%s: (%d, %d, %d)", RideTypeDescriptors[ride.type].EnumName, static_cast<int>(ratings.Excitement),
|
||||
static_cast<int>(ratings.Intensity), static_cast<int>(ratings.Nausea));
|
||||
return line;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -455,7 +455,8 @@ static void CompareStates(
|
||||
{
|
||||
log_warning(
|
||||
"Inconsistent export size! Import Size: %llu bytes, Export Size: %llu bytes",
|
||||
(unsigned long long)importBuffer.GetLength(), (unsigned long long)exportBuffer.GetLength());
|
||||
static_cast<unsigned long long>(importBuffer.GetLength()),
|
||||
static_cast<unsigned long long>(exportBuffer.GetLength()));
|
||||
}
|
||||
|
||||
for (size_t spriteIdx = 0; spriteIdx < MAX_SPRITES; ++spriteIdx)
|
||||
|
||||
Reference in New Issue
Block a user