diff --git a/src/openrct2-ui/drawing/engines/opengl/OpenGLAPI.cpp b/src/openrct2-ui/drawing/engines/opengl/OpenGLAPI.cpp index 6408a2217d..277222f857 100644 --- a/src/openrct2-ui/drawing/engines/opengl/OpenGLAPI.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/OpenGLAPI.cpp @@ -24,7 +24,7 @@ static const char* TryLoadAllProcAddresses() { # define OPENGL_PROC(TYPE, PROC) \ { \ - PROC = (TYPE)SDL_GL_GetProcAddress(#PROC); \ + PROC = reinterpret_cast(SDL_GL_GetProcAddress(#PROC)); \ if (PROC == nullptr) \ { \ return #PROC; \ diff --git a/src/openrct2-ui/windows/GuestList.cpp b/src/openrct2-ui/windows/GuestList.cpp index 899fe72f93..01bf93644a 100644 --- a/src/openrct2-ui/windows/GuestList.cpp +++ b/src/openrct2-ui/windows/GuestList.cpp @@ -266,7 +266,7 @@ void window_guest_list_refresh_list() GuestList.push_back(spriteIndex); } - std::sort(GuestList.begin(), GuestList.end(), [](const uint16_t a, const uint16_t b) { return peep_compare(&a, &b) < 0; }); + std::sort(GuestList.begin(), GuestList.end(), [](const uint16_t a, const uint16_t b) { return peep_compare(a, b) < 0; }); } /** diff --git a/src/openrct2-ui/windows/StaffList.cpp b/src/openrct2-ui/windows/StaffList.cpp index 868efe9725..1e28989da9 100644 --- a/src/openrct2-ui/windows/StaffList.cpp +++ b/src/openrct2-ui/windows/StaffList.cpp @@ -200,7 +200,7 @@ void WindowStaffListRefresh() StaffList.push_back(spriteIndex); } - std::sort(StaffList.begin(), StaffList.end(), [](const uint16_t a, const uint16_t b) { return peep_compare(&a, &b) < 0; }); + std::sort(StaffList.begin(), StaffList.end(), [](const uint16_t a, const uint16_t b) { return peep_compare(a, b) < 0; }); } static void window_staff_list_cancel_tools(rct_window* w) diff --git a/src/openrct2/cmdline/BenchSpriteSort.cpp b/src/openrct2/cmdline/BenchSpriteSort.cpp index 45cdb8b6f2..3ace2f7cfc 100644 --- a/src/openrct2/cmdline/BenchSpriteSort.cpp +++ b/src/openrct2/cmdline/BenchSpriteSort.cpp @@ -46,9 +46,8 @@ static void fixup_pointers(paint_session* s, size_t paint_session_entries, size_ } else { - s[i].PaintStructs[j].basic.next_quadrant_ps = &s[i].PaintStructs - [(uintptr_t)s[i].PaintStructs[j].basic.next_quadrant_ps] - .basic; + auto nextQuadrantPs = reinterpret_cast(s[i].PaintStructs[j].basic.next_quadrant_ps); + s[i].PaintStructs[j].basic.next_quadrant_ps = &s[i].PaintStructs[nextQuadrantPs].basic; } } for (size_t j = 0; j < quadrant_entries; j++) diff --git a/src/openrct2/core/Crypt.OpenSSL.cpp b/src/openrct2/core/Crypt.OpenSSL.cpp index b700a5ad8e..6140a16dca 100644 --- a/src/openrct2/core/Crypt.OpenSSL.cpp +++ b/src/openrct2/core/Crypt.OpenSSL.cpp @@ -183,7 +183,7 @@ private: { // Read PEM data via BIO buffer // HACK first parameter is not const on MINGW for some reason - auto bio = BIO_new_mem_buf((void*)pem.data(), static_cast(pem.size())); + auto bio = BIO_new_mem_buf(static_cast(pem.data()), static_cast(pem.size())); if (bio == nullptr) { throw std::runtime_error("BIO_new_mem_buf failed"); @@ -307,7 +307,7 @@ public: status = EVP_DigestVerifyUpdate(mdctx, data, dataLen); OpenSSLThrowOnBadStatus("EVP_DigestVerifyUpdate", status); - status = EVP_DigestVerifyFinal(mdctx, (uint8_t*)sig, sigLen); + status = EVP_DigestVerifyFinal(mdctx, static_cast(sig), sigLen); if (status != 0 && status != 1) { OpenSSLThrowOnBadStatus("EVP_DigestVerifyUpdate", status); diff --git a/src/openrct2/core/MemoryStream.cpp b/src/openrct2/core/MemoryStream.cpp index 06808cf2d7..318bb5a8bb 100644 --- a/src/openrct2/core/MemoryStream.cpp +++ b/src/openrct2/core/MemoryStream.cpp @@ -24,7 +24,7 @@ MemoryStream::MemoryStream(const MemoryStream& copy) { _data = Memory::Allocate(_dataCapacity); std::memcpy(_data, copy._data, _dataCapacity); - _position = (void*)((uintptr_t)_data + copy.GetPosition()); + _position = reinterpret_cast(reinterpret_cast(_data) + copy.GetPosition()); } } @@ -115,7 +115,7 @@ uint64_t MemoryStream::GetLength() const uint64_t MemoryStream::GetPosition() const { - return static_cast((uintptr_t)_position - (uintptr_t)_data); + return static_cast(reinterpret_cast(_position) - reinterpret_cast(_data)); } void MemoryStream::SetPosition(uint64_t position) @@ -144,7 +144,7 @@ void MemoryStream::Seek(int64_t offset, int32_t origin) { throw IOException("New position out of bounds."); } - _position = (void*)((uintptr_t)_data + static_cast(newPosition)); + _position = reinterpret_cast(reinterpret_cast(_data) + static_cast(newPosition)); } void MemoryStream::Read(void* buffer, uint64_t length) @@ -156,7 +156,7 @@ void MemoryStream::Read(void* buffer, uint64_t length) } std::memcpy(buffer, _position, length); - _position = (void*)((uintptr_t)_position + length); + _position = reinterpret_cast(reinterpret_cast(_position) + length); } void MemoryStream::Read1(void* buffer) @@ -209,7 +209,7 @@ void MemoryStream::Write(const void* buffer, uint64_t length) } std::memcpy(_position, buffer, length); - _position = (void*)((uintptr_t)_position + length); + _position = reinterpret_cast(reinterpret_cast(_position) + length); _dataSize = std::max(_dataSize, static_cast(nextPosition)); } @@ -251,6 +251,6 @@ void MemoryStream::EnsureCapacity(size_t capacity) uint64_t position = GetPosition(); _dataCapacity = newCapacity; _data = Memory::Reallocate(_data, _dataCapacity); - _position = (void*)((uintptr_t)_data + static_cast(position)); + _position = reinterpret_cast(reinterpret_cast(_data) + static_cast(position)); } } diff --git a/src/openrct2/core/MemoryStream.h b/src/openrct2/core/MemoryStream.h index 17fb778e78..7f5bc0a55b 100644 --- a/src/openrct2/core/MemoryStream.h +++ b/src/openrct2/core/MemoryStream.h @@ -75,7 +75,7 @@ public: } std::memcpy(buffer, _position, N); - _position = (void*)((uintptr_t)_position + N); + _position = reinterpret_cast(reinterpret_cast(_position) + N); } void Write(const void* buffer, uint64_t length) override; @@ -102,7 +102,7 @@ public: } std::memcpy(_position, buffer, N); - _position = (void*)((uintptr_t)_position + N); + _position = reinterpret_cast(reinterpret_cast(_position) + N); _dataSize = std::max(_dataSize, static_cast(nextPosition)); } diff --git a/src/openrct2/core/String.cpp b/src/openrct2/core/String.cpp index f764ccb17b..a4efe37907 100644 --- a/src/openrct2/core/String.cpp +++ b/src/openrct2/core/String.cpp @@ -85,7 +85,7 @@ namespace String icu::UnicodeString str = icu::UnicodeString::fromUTF32(reinterpret_cast(src.data()), src.length()); # elif U_SIZEOF_WCHAR_T == 2 std::wstring wstr = std::wstring(src); - icu::UnicodeString str = icu::UnicodeString((const wchar_t*)wstr.c_str()); + icu::UnicodeString str = icu::UnicodeString(static_cast(wstr.c_str())); # else # error Unsupported U_SIZEOF_WCHAR_T size # endif @@ -120,7 +120,7 @@ namespace String # elif U_SIZEOF_WCHAR_T == 2 const char16_t* buffer = str.getBuffer(); - std::wstring result = (wchar_t*)buffer; + std::wstring result = static_cast(buffer); # else # error Unsupported U_SIZEOF_WCHAR_T size diff --git a/src/openrct2/core/ZipAndroid.cpp b/src/openrct2/core/ZipAndroid.cpp index 3625a40b58..f39978b715 100644 --- a/src/openrct2/core/ZipAndroid.cpp +++ b/src/openrct2/core/ZipAndroid.cpp @@ -163,7 +163,7 @@ JNIEXPORT jlong JNICALL Java_io_openrct2_ZipArchive_allocBytes(JNIEnv* env, jcla env->ReleaseByteArrayElements(input, bufferPtr, 0); - return (uintptr_t)data; + return reinterpret_cast(data); } #endif // __ANDROID__ diff --git a/src/openrct2/drawing/Drawing.Sprite.cpp b/src/openrct2/drawing/Drawing.Sprite.cpp index e309fd6c75..a0cd31a53a 100644 --- a/src/openrct2/drawing/Drawing.Sprite.cpp +++ b/src/openrct2/drawing/Drawing.Sprite.cpp @@ -103,7 +103,7 @@ static void read_and_convert_gxdat(IStream* stream, size_t count, bool is_rctc, // Double cast to silence compiler warning about casting to // pointer from integer of mismatched length. - elements[i].offset = (uint8_t*)static_cast(src.offset); + elements[i].offset = reinterpret_cast(static_cast(src.offset)); elements[i].width = src.width; elements[i].height = src.height; elements[i].x_offset = src.x_offset; @@ -142,7 +142,7 @@ static void read_and_convert_gxdat(IStream* stream, size_t count, bool is_rctc, // Double cast to silence compiler warning about casting to // pointer from integer of mismatched length. - elements[i].offset = (uint8_t*)static_cast(src.offset); + elements[i].offset = reinterpret_cast(static_cast(src.offset)); elements[i].width = src.width; elements[i].height = src.height; elements[i].x_offset = src.x_offset; @@ -218,7 +218,7 @@ bool gfx_load_g1(const IPlatformEnvironment& env) // Fix entry data offsets for (uint32_t i = 0; i < _g1.header.num_entries; i++) { - _g1.elements[i].offset += (uintptr_t)_g1.data; + _g1.elements[i].offset += reinterpret_cast(_g1.data); } return true; } @@ -281,7 +281,7 @@ bool gfx_load_g2() // Fix entry data offsets for (uint32_t i = 0; i < _g2.header.num_entries; i++) { - _g2.elements[i].offset += (uintptr_t)_g2.data; + _g2.elements[i].offset += reinterpret_cast(_g2.data); } return true; } @@ -338,7 +338,7 @@ bool gfx_load_csg() // Fix entry data offsets for (uint32_t i = 0; i < _csg.header.num_entries; i++) { - _csg.elements[i].offset += (uintptr_t)_csg.data; + _csg.elements[i].offset += reinterpret_cast(_csg.data); // RCT1 used zoomed offsets that counted from the beginning of the file, rather than from the current sprite. if (_csg.elements[i].flags & G1_FLAG_HAS_ZOOM_SPRITE) { diff --git a/src/openrct2/drawing/LightFX.cpp b/src/openrct2/drawing/LightFX.cpp index 3e3f9baffd..8295b150c4 100644 --- a/src/openrct2/drawing/LightFX.cpp +++ b/src/openrct2/drawing/LightFX.cpp @@ -1008,7 +1008,7 @@ void lightfx_render_to_texture( for (uint32_t y = 0; y < height; y++) { uintptr_t dstOffset = static_cast(y * dstPitch); - uint32_t* dst = (uint32_t*)((uintptr_t)dstPixels + dstOffset); + uint32_t* dst = reinterpret_cast(reinterpret_cast(dstPixels) + dstOffset); for (uint32_t x = 0; x < width; x++) { uint8_t* src = &bits[y * width + x]; diff --git a/src/openrct2/drawing/TTF.cpp b/src/openrct2/drawing/TTF.cpp index e20a727ecd..3efa364edc 100644 --- a/src/openrct2/drawing/TTF.cpp +++ b/src/openrct2/drawing/TTF.cpp @@ -183,7 +183,7 @@ static void ttf_close_font(TTF_Font* font) static uint32_t ttf_surface_cache_hash(TTF_Font* font, const utf8* text) { - uint32_t hash = static_cast((((uintptr_t)font * 23) ^ 0xAAAAAAAA) & 0xFFFFFFFF); + uint32_t hash = static_cast(((reinterpret_cast(font) * 23) ^ 0xAAAAAAAA) & 0xFFFFFFFF); for (const utf8* ch = text; *ch != 0; ch++) { hash = ror32(hash, 3) ^ (*ch * 13); diff --git a/src/openrct2/drawing/TTFSDLPort.cpp b/src/openrct2/drawing/TTFSDLPort.cpp index 43eaf85e7b..7be6922cf3 100644 --- a/src/openrct2/drawing/TTFSDLPort.cpp +++ b/src/openrct2/drawing/TTFSDLPort.cpp @@ -205,7 +205,7 @@ static void TTF_initLineMectrics(const TTF_Font* font, const TTFSurface* textbuf uint8_t* dst; int height; - dst = (uint8_t*)textbuf->pixels; + dst = const_cast(static_cast(textbuf->pixels)); if (row > 0) { dst += row * textbuf->pitch; @@ -228,7 +228,7 @@ outline into account. static void TTF_drawLine_Solid(const TTF_Font* font, const TTFSurface* textbuf, const int row) { int line; - uint8_t* dst_check = (uint8_t*)textbuf->pixels + textbuf->pitch * textbuf->h; + uint8_t* dst_check = const_cast(static_cast(textbuf->pixels)) + textbuf->pitch * textbuf->h; uint8_t* dst; int height; @@ -250,7 +250,7 @@ static void TTF_drawLine_Solid(const TTF_Font* font, const TTFSurface* textbuf, static void TTF_drawLine_Shaded(const TTF_Font* font, const TTFSurface* textbuf, const int row) { int line; - uint8_t* dst_check = (uint8_t*)textbuf->pixels + textbuf->pitch * textbuf->h; + uint8_t* dst_check = const_cast(static_cast(textbuf->pixels)) + textbuf->pitch * textbuf->h; uint8_t* dst; int height; @@ -1296,7 +1296,7 @@ TTFSurface* TTF_RenderUTF8_Solid(TTF_Font* font, const char* text, [[maybe_unuse /* Adding bound checking to avoid all kinds of memory corruption errors that may occur. */ - dst_check = (uint8_t*)textbuf->pixels + textbuf->pitch * textbuf->h; + dst_check = const_cast(static_cast(textbuf->pixels)) + textbuf->pitch * textbuf->h; /* check kerning */ use_kerning = FT_HAS_KERNING(font->face) && font->kerning; @@ -1355,7 +1355,8 @@ TTFSurface* TTF_RenderUTF8_Solid(TTF_Font* font, const char* text, [[maybe_unuse { continue; } - dst = (uint8_t*)textbuf->pixels + (row + glyph->yoffset) * textbuf->pitch + xstart + glyph->minx; + dst = const_cast(static_cast(textbuf->pixels)) + (row + glyph->yoffset) * textbuf->pitch + + xstart + glyph->minx; src = current->buffer + row * current->pitch; for (col = width; col > 0 && dst < dst_check; --col) @@ -1428,7 +1429,7 @@ TTFSurface* TTF_RenderUTF8_Shaded(TTF_Font* font, const char* text, [[maybe_unus /* Adding bound checking to avoid all kinds of memory corruption errors that may occur. */ - dst_check = (uint8_t*)textbuf->pixels + textbuf->pitch * textbuf->h; + dst_check = const_cast(static_cast(textbuf->pixels)) + textbuf->pitch * textbuf->h; /* check kerning */ use_kerning = FT_HAS_KERNING(font->face) && font->kerning; @@ -1492,7 +1493,8 @@ TTFSurface* TTF_RenderUTF8_Shaded(TTF_Font* font, const char* text, [[maybe_unus continue; } - dst = (uint8_t*)textbuf->pixels + (row + glyph->yoffset) * textbuf->pitch + xstart + glyph->minx; + dst = const_cast(static_cast(textbuf->pixels)) + (row + glyph->yoffset) * textbuf->pitch + + xstart + glyph->minx; src = current->buffer + row * current->pitch; for (col = width; col > 0 && dst < dst_check; --col) diff --git a/src/openrct2/network/NetworkPacket.cpp b/src/openrct2/network/NetworkPacket.cpp index 2fc388e0b2..865c83a5b8 100644 --- a/src/openrct2/network/NetworkPacket.cpp +++ b/src/openrct2/network/NetworkPacket.cpp @@ -71,7 +71,7 @@ void NetworkPacket::Write(const uint8_t* bytes, size_t size) void NetworkPacket::WriteString(const utf8* string) { - Write((uint8_t*)string, strlen(string) + 1); + Write(reinterpret_cast(string), strlen(string) + 1); } const uint8_t* NetworkPacket::Read(size_t size) diff --git a/src/openrct2/object/ImageTable.cpp b/src/openrct2/object/ImageTable.cpp index 1331325fe9..9b2f1eb944 100644 --- a/src/openrct2/object/ImageTable.cpp +++ b/src/openrct2/object/ImageTable.cpp @@ -57,7 +57,7 @@ void ImageTable::Read(IReadObjectContext* context, IStream* stream) } // Read g1 element headers - uintptr_t imageDataBase = (uintptr_t)data.get(); + uintptr_t imageDataBase = reinterpret_cast(data.get()); std::vector newEntries; for (uint32_t i = 0; i < numImages; i++) { diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index 4c74dccbcf..6cb641ad29 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -3251,10 +3251,10 @@ rct_string_id get_real_name_string_id_from_id(uint32_t id) return dx; } -int32_t peep_compare(const void* sprite_index_a, const void* sprite_index_b) +int32_t peep_compare(const uint16_t sprite_index_a, const uint16_t sprite_index_b) { - Peep const* peep_a = GET_PEEP(*(uint16_t*)sprite_index_a); - Peep const* peep_b = GET_PEEP(*(uint16_t*)sprite_index_b); + Peep const* peep_a = GET_PEEP(sprite_index_a); + Peep const* peep_b = GET_PEEP(sprite_index_b); // Compare types if (peep_a->type != peep_b->type) diff --git a/src/openrct2/peep/Peep.h b/src/openrct2/peep/Peep.h index 432f1dda37..b643e3a796 100644 --- a/src/openrct2/peep/Peep.h +++ b/src/openrct2/peep/Peep.h @@ -1044,7 +1044,7 @@ void peep_window_state_update(Peep* peep); void peep_decrement_num_riders(Peep* peep); void peep_set_map_tooltip(Peep* peep); -int32_t peep_compare(const void* sprite_index_a, const void* sprite_index_b); +int32_t peep_compare(const uint16_t sprite_index_a, const uint16_t sprite_index_b); void SwitchToSpecialSprite(Peep* peep, uint8_t special_sprite_id); void peep_update_names(bool realNames);