mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 04:09:13 +00:00
AK: Don't assert things about active union members in StringBase
This involves yeeting the 'invalid' union member as it was not really checked against properly anyway; now the 'invalid' state is simply StringData*{nullptr}, which was assumed to not exist previously. Note that this is still accessing inactive union members, but is promising to the compiler that they're fine where they are (the provided debug macro AK_STRINGBASE_VERIFY_LAUNDER_DEBUG makes the would-be-UB-if-not-for-launder ops verify that the operation is correct) Should fix the GCC build.
This commit is contained in:
parent
c39eddaef8
commit
a83145c751
Notes:
github-actions[bot]
2025-03-27 16:05:24 +00:00
Author: https://github.com/alimpfard
Commit: a83145c751
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4105
Reviewed-by: https://github.com/gmta ✅
Reviewed-by: https://github.com/trflynn89 ✅
7 changed files with 96 additions and 60 deletions
|
@ -13,7 +13,6 @@ namespace AK::Detail {
|
|||
|
||||
void StringBase::replace_with_string_builder(StringBuilder& builder)
|
||||
{
|
||||
ASSERT(!is_invalid());
|
||||
if (builder.length() <= MAX_SHORT_STRING_BYTE_COUNT) {
|
||||
return replace_with_new_short_string(builder.length(), [&](Bytes buffer) {
|
||||
builder.string_view().bytes().copy_to(buffer);
|
||||
|
@ -22,24 +21,22 @@ void StringBase::replace_with_string_builder(StringBuilder& builder)
|
|||
|
||||
destroy_string();
|
||||
|
||||
m_data = &StringData::create_from_string_builder(builder).leak_ref();
|
||||
m_impl = { .data = &StringData::create_from_string_builder(builder).leak_ref() };
|
||||
}
|
||||
|
||||
ErrorOr<Bytes> StringBase::replace_with_uninitialized_buffer(size_t byte_count)
|
||||
{
|
||||
ASSERT(!is_invalid());
|
||||
if (byte_count <= MAX_SHORT_STRING_BYTE_COUNT)
|
||||
return replace_with_uninitialized_short_string(byte_count);
|
||||
|
||||
u8* buffer = nullptr;
|
||||
destroy_string();
|
||||
m_data = &TRY(StringData::create_uninitialized(byte_count, buffer)).leak_ref();
|
||||
m_impl = { .data = &TRY(StringData::create_uninitialized(byte_count, buffer)).leak_ref() };
|
||||
return Bytes { buffer, byte_count };
|
||||
}
|
||||
|
||||
ErrorOr<StringBase> StringBase::substring_from_byte_offset_with_shared_superstring(size_t start, size_t length) const
|
||||
{
|
||||
ASSERT(!is_invalid());
|
||||
VERIFY(start + length <= byte_count());
|
||||
|
||||
if (length == 0)
|
||||
|
@ -49,7 +46,6 @@ ErrorOr<StringBase> StringBase::substring_from_byte_offset_with_shared_superstri
|
|||
bytes().slice(start, length).copy_to(result.replace_with_uninitialized_short_string(length));
|
||||
return result;
|
||||
}
|
||||
return StringBase { TRY(Detail::StringData::create_substring(*m_data, start, length)) };
|
||||
return StringBase { TRY(Detail::StringData::create_substring(*m_impl.data, start, length)) };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue