diff --git a/AK/Bitmap.h b/AK/Bitmap.h index 78a7735af9..671942de02 100644 --- a/AK/Bitmap.h +++ b/AK/Bitmap.h @@ -30,7 +30,7 @@ public: if (!data) return Error::from_errno(ENOMEM); - auto bitmap = Bitmap { (u8*)data, size, true }; + auto bitmap = Bitmap { static_cast(data), size, true }; bitmap.fill(default_value); return bitmap; } diff --git a/AK/BitmapView.h b/AK/BitmapView.h index 3e026db2b4..1bfb823567 100644 --- a/AK/BitmapView.h +++ b/AK/BitmapView.h @@ -64,19 +64,19 @@ public: count += popcount(byte); } if (++first < last) { - size_t const* ptr_large = (size_t const*)(((FlatPtr)first + sizeof(size_t) - 1) & ~(sizeof(size_t) - 1)); - if ((u8 const*)ptr_large > last) - ptr_large = (size_t const*)last; - while (first < (u8 const*)ptr_large) { + size_t const* ptr_large = reinterpret_cast((reinterpret_cast(first) + sizeof(size_t) - 1) & ~(sizeof(size_t) - 1)); + if (reinterpret_cast(ptr_large) > last) + ptr_large = reinterpret_cast(last); + while (first < reinterpret_cast(ptr_large)) { count += popcount(*first); first++; } - size_t const* last_large = (size_t const*)((FlatPtr)last & ~(sizeof(size_t) - 1)); + size_t const* last_large = reinterpret_cast(reinterpret_cast(last) & ~(sizeof(size_t) - 1)); while (ptr_large < last_large) { count += popcount(*ptr_large); ptr_large++; } - for (first = (u8 const*)ptr_large; first < last; first++) + for (first = reinterpret_cast(ptr_large); first < last; first++) count += popcount(*first); } } @@ -100,12 +100,12 @@ public: // We will use hint as what it is: a hint. Because we try to // scan over entire 32 bit words, we may start searching before // the hint! - size_t const* ptr_large = (size_t const*)((FlatPtr)&m_data[hint / 8] & ~(sizeof(size_t) - 1)); - if ((u8 const*)ptr_large < &m_data[0]) { + size_t const* ptr_large = reinterpret_cast(reinterpret_cast(&m_data[hint / 8]) & ~(sizeof(size_t) - 1)); + if (reinterpret_cast(ptr_large) < &m_data[0]) { ptr_large++; // m_data isn't aligned, check first bytes - size_t start_ptr_large = (u8 const*)ptr_large - &m_data[0]; + size_t start_ptr_large = reinterpret_cast(ptr_large) - &m_data[0]; size_t i = 0; u8 byte = VALUE ? 0x00 : 0xff; while (i < start_ptr_large && m_data[i] == byte) @@ -120,14 +120,14 @@ public: } size_t val_large = VALUE ? 0x0 : NumericLimits::max(); - size_t const* end_large = (size_t const*)((FlatPtr)end & ~(sizeof(size_t) - 1)); + size_t const* end_large = reinterpret_cast(reinterpret_cast(end) & ~(sizeof(size_t) - 1)); while (ptr_large < end_large && *ptr_large == val_large) ptr_large++; if (ptr_large == end_large) { // We didn't find anything, check the remaining few bytes (if any) u8 byte = VALUE ? 0x00 : 0xff; - size_t i = (u8 const*)ptr_large - &m_data[0]; + size_t i = reinterpret_cast(ptr_large) - &m_data[0]; size_t byte_count = m_size / 8; VERIFY(i <= byte_count); while (i < byte_count && m_data[i] == byte) @@ -137,7 +137,7 @@ public: return {}; // We already checked from the beginning // Try scanning before the hint - end = (u8 const*)((FlatPtr)&m_data[hint / 8] & ~(sizeof(size_t) - 1)); + end = reinterpret_cast(reinterpret_cast(&m_data[hint / 8]) & ~(sizeof(size_t) - 1)); hint = 0; continue; } @@ -154,7 +154,7 @@ public: if constexpr (!VALUE) val_large = ~val_large; VERIFY(val_large != 0); - return ((u8 const*)ptr_large - &m_data[0]) * 8 + bit_scan_forward(val_large) - 1; + return (reinterpret_cast(ptr_large) - &m_data[0]) * 8 + bit_scan_forward(val_large) - 1; } } @@ -207,7 +207,7 @@ public: size_t bit_size = 8 * sizeof(size_t); - size_t* bitmap = (size_t*)m_data; + size_t* bitmap = reinterpret_cast(m_data); // Calculating the start offset. size_t start_bucket_index = from / bit_size; diff --git a/AK/BumpAllocator.h b/AK/BumpAllocator.h index 81cd9dbf19..21348a4df0 100644 --- a/AK/BumpAllocator.h +++ b/AK/BumpAllocator.h @@ -65,7 +65,7 @@ public: for_each_chunk([&](auto chunk) { if (!cache_filled) { cache_filled = true; - ((ChunkHeader*)chunk)->next_chunk = 0; + (reinterpret_cast(chunk))->next_chunk = 0; chunk = s_unused_allocation_cache.exchange(chunk); if (!chunk) return; @@ -86,7 +86,7 @@ protected: { auto head_chunk = m_head_chunk; while (head_chunk) { - auto& chunk_header = *(ChunkHeader const*)head_chunk; + auto& chunk_header = *reinterpret_cast(head_chunk); VERIFY(chunk_header.magic == chunk_magic); if (head_chunk == m_current_chunk) VERIFY(chunk_header.next_chunk == 0); @@ -100,7 +100,7 @@ protected: { // dbgln("Allocated {} entries in previous chunk and have {} unusable bytes", m_allocations_in_previous_chunk, m_chunk_size - m_byte_offset_into_current_chunk); // m_allocations_in_previous_chunk = 0; - void* new_chunk = (void*)s_unused_allocation_cache.exchange(0); + void* new_chunk = reinterpret_cast(s_unused_allocation_cache.exchange(0)); if (!new_chunk) { if constexpr (use_mmap) { #ifdef AK_OS_SERENITY @@ -117,24 +117,24 @@ protected: } } - auto& new_header = *(ChunkHeader*)new_chunk; + auto& new_header = *reinterpret_cast(new_chunk); new_header.magic = chunk_magic; new_header.next_chunk = 0; m_byte_offset_into_current_chunk = sizeof(ChunkHeader); if (!m_head_chunk) { VERIFY(!m_current_chunk); - m_head_chunk = (FlatPtr)new_chunk; - m_current_chunk = (FlatPtr)new_chunk; + m_head_chunk = reinterpret_cast(new_chunk); + m_current_chunk = reinterpret_cast(new_chunk); return true; } VERIFY(m_current_chunk); - auto& old_header = *(ChunkHeader*)m_current_chunk; + auto& old_header = *reinterpret_cast(m_current_chunk); VERIFY(old_header.magic == chunk_magic); VERIFY(old_header.next_chunk == 0); - old_header.next_chunk = (FlatPtr)new_chunk; - m_current_chunk = (FlatPtr)new_chunk; + old_header.next_chunk = reinterpret_cast(new_chunk); + m_current_chunk = reinterpret_cast(new_chunk); return true; } diff --git a/AK/ByteBuffer.h b/AK/ByteBuffer.h index 61ebf051a6..064613f095 100644 --- a/AK/ByteBuffer.h +++ b/AK/ByteBuffer.h @@ -296,7 +296,7 @@ private: // This is most noticable in Lagom, where kmalloc_good_size is just a no-op. new_capacity = max(new_capacity, (capacity() * 3) / 2); new_capacity = kmalloc_good_size(new_capacity); - auto* new_buffer = (u8*)kmalloc(new_capacity); + auto* new_buffer = static_cast(kmalloc(new_capacity)); if (!new_buffer) return Error::from_errno(ENOMEM); diff --git a/AK/DeprecatedString.h b/AK/DeprecatedString.h index 98e264385e..9f6091404d 100644 --- a/AK/DeprecatedString.h +++ b/AK/DeprecatedString.h @@ -276,7 +276,7 @@ public: { if (buffer.is_empty()) return empty(); - return DeprecatedString((char const*)buffer.data(), buffer.size(), should_chomp); + return DeprecatedString(reinterpret_cast(buffer.data()), buffer.size(), should_chomp); } [[nodiscard]] static DeprecatedString vformatted(StringView fmtstr, TypeErasedFormatParams&); diff --git a/AK/NonnullOwnPtr.h b/AK/NonnullOwnPtr.h index 5f9b516c4f..26f8d6b0f5 100644 --- a/AK/NonnullOwnPtr.h +++ b/AK/NonnullOwnPtr.h @@ -188,7 +188,7 @@ template struct Traits> : public GenericTraits> { using PeekType = T*; using ConstPeekType = T const*; - static unsigned hash(NonnullOwnPtr const& p) { return ptr_hash((FlatPtr)p.ptr()); } + static unsigned hash(NonnullOwnPtr const& p) { return ptr_hash(p.ptr()); } static bool equals(NonnullOwnPtr const& a, NonnullOwnPtr const& b) { return a.ptr() == b.ptr(); } }; diff --git a/AK/StdLibExtras.h b/AK/StdLibExtras.h index 67e6b3ac3b..c369322c26 100644 --- a/AK/StdLibExtras.h +++ b/AK/StdLibExtras.h @@ -134,8 +134,8 @@ inline void swap(T& a, U& b) { if (&a == &b) return; - U tmp = move((U&)a); - a = (T &&) move(b); + U tmp = move(static_cast(a)); + a = static_cast(move(b)); b = move(tmp); } diff --git a/AK/StringHash.h b/AK/StringHash.h index 396fefb116..b5966adb3c 100644 --- a/AK/StringHash.h +++ b/AK/StringHash.h @@ -14,7 +14,7 @@ constexpr u32 string_hash(char const* characters, size_t length, u32 seed = 0) { u32 hash = seed; for (size_t i = 0; i < length; ++i) { - hash += (u32)characters[i]; + hash += static_cast(characters[i]); hash += (hash << 10); hash ^= (hash >> 6); } diff --git a/AK/StringView.h b/AK/StringView.h index 027ad6a886..dd6fe9540e 100644 --- a/AK/StringView.h +++ b/AK/StringView.h @@ -26,13 +26,13 @@ public: , m_length(length) { if (!is_constant_evaluated()) - VERIFY(!Checked::addition_would_overflow((uintptr_t)characters, length)); + VERIFY(!Checked::addition_would_overflow(reinterpret_cast(characters), length)); } ALWAYS_INLINE StringView(unsigned char const* characters, size_t length) - : m_characters((char const*)characters) + : m_characters(reinterpret_cast(characters)) , m_length(length) { - VERIFY(!Checked::addition_would_overflow((uintptr_t)characters, length)); + VERIFY(!Checked::addition_would_overflow(reinterpret_cast(characters), length)); } ALWAYS_INLINE StringView(ReadonlyBytes bytes) : m_characters(reinterpret_cast(bytes.data())) diff --git a/AK/Traits.h b/AK/Traits.h index 901d97ed5d..29334b41f7 100644 --- a/AK/Traits.h +++ b/AK/Traits.h @@ -59,7 +59,7 @@ struct Traits : public GenericTraits { template requires(IsPointer && !Detail::IsPointerOfType) struct Traits : public GenericTraits { - static unsigned hash(T p) { return ptr_hash((FlatPtr)p); } + static unsigned hash(T p) { return ptr_hash(p); } static constexpr bool is_trivial() { return true; } }; diff --git a/AK/Types.h b/AK/Types.h index 4c9d26e019..c60a5ed183 100644 --- a/AK/Types.h +++ b/AK/Types.h @@ -97,9 +97,9 @@ static constexpr FlatPtr explode_byte(u8 b) return value << 56 | value << 48 | value << 40 | value << 32 | value << 24 | value << 16 | value << 8 | value; } -static_assert(explode_byte(0xff) == (FlatPtr)0xffffffffffffffffull); -static_assert(explode_byte(0x80) == (FlatPtr)0x8080808080808080ull); -static_assert(explode_byte(0x7f) == (FlatPtr)0x7f7f7f7f7f7f7f7full); +static_assert(explode_byte(0xff) == static_cast(0xffffffffffffffffull)); +static_assert(explode_byte(0x80) == static_cast(0x8080808080808080ull)); +static_assert(explode_byte(0x7f) == static_cast(0x7f7f7f7f7f7f7f7full)); static_assert(explode_byte(0) == 0); constexpr size_t align_up_to(const size_t value, const size_t alignment) diff --git a/AK/UnicodeUtils.h b/AK/UnicodeUtils.h index fd55dd611d..691ad0fb6f 100644 --- a/AK/UnicodeUtils.h +++ b/AK/UnicodeUtils.h @@ -16,22 +16,22 @@ template [[nodiscard]] constexpr int code_point_to_utf8(u32 code_point, Callback callback) { if (code_point <= 0x7f) { - callback((char)code_point); + callback(static_cast(code_point)); return 1; } else if (code_point <= 0x07ff) { - callback((char)(((code_point >> 6) & 0x1f) | 0xc0)); - callback((char)(((code_point >> 0) & 0x3f) | 0x80)); + callback(static_cast(((code_point >> 6) & 0x1f) | 0xc0)); + callback(static_cast(((code_point >> 0) & 0x3f) | 0x80)); return 2; } else if (code_point <= 0xffff) { - callback((char)(((code_point >> 12) & 0x0f) | 0xe0)); - callback((char)(((code_point >> 6) & 0x3f) | 0x80)); - callback((char)(((code_point >> 0) & 0x3f) | 0x80)); + callback(static_cast(((code_point >> 12) & 0x0f) | 0xe0)); + callback(static_cast(((code_point >> 6) & 0x3f) | 0x80)); + callback(static_cast(((code_point >> 0) & 0x3f) | 0x80)); return 3; } else if (code_point <= 0x10ffff) { - callback((char)(((code_point >> 18) & 0x07) | 0xf0)); - callback((char)(((code_point >> 12) & 0x3f) | 0x80)); - callback((char)(((code_point >> 6) & 0x3f) | 0x80)); - callback((char)(((code_point >> 0) & 0x3f) | 0x80)); + callback(static_cast(((code_point >> 18) & 0x07) | 0xf0)); + callback(static_cast(((code_point >> 12) & 0x3f) | 0x80)); + callback(static_cast(((code_point >> 6) & 0x3f) | 0x80)); + callback(static_cast(((code_point >> 0) & 0x3f) | 0x80)); return 4; } return -1; diff --git a/AK/Userspace.h b/AK/Userspace.h index 62bf0d10d4..1d4e4f36b8 100644 --- a/AK/Userspace.h +++ b/AK/Userspace.h @@ -68,7 +68,7 @@ inline Userspace static_ptr_cast(Userspace const& ptr) #else auto casted_ptr = static_cast(ptr.ptr()); #endif - return Userspace((FlatPtr)casted_ptr); + return Userspace(reinterpret_cast(casted_ptr)); } } diff --git a/AK/Utf8View.h b/AK/Utf8View.h index a16ae5d88c..7b51db861c 100644 --- a/AK/Utf8View.h +++ b/AK/Utf8View.h @@ -158,7 +158,7 @@ public: private: friend class Utf8CodePointIterator; - u8 const* begin_ptr() const { return (u8 const*)m_string.characters_without_null_termination(); } + u8 const* begin_ptr() const { return reinterpret_cast(m_string.characters_without_null_termination()); } u8 const* end_ptr() const { return begin_ptr() + m_string.length(); } size_t calculate_length() const;