Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Source/WTF/wtf/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,17 @@ struct VectorTypeOperations
}
};

#if USE(BUN_JSC_ADDITIONS)
// m_capacity counts elements in 31 bits, next to the borrow bit. 310668@main halved the limit on the size in bytes
// instead, which halved the capacity of every Vector whose T is wider than a byte. This keeps the limit on the size
// in bytes from before that change and adds the limit on the count.
template<typename T>
constexpr inline bool isValidCapacityForVector(size_t capacity) { return capacity <= std::min<size_t>(std::numeric_limits<unsigned>::max() / sizeof(T), std::numeric_limits<unsigned>::max() >> 1); }
static_assert(isValidCapacityForVector<uint8_t>(std::numeric_limits<unsigned>::max() >> 1) && !isValidCapacityForVector<uint8_t>((std::numeric_limits<unsigned>::max() >> 1) + 1), "a valid capacity fits in the 31 bits of m_capacity");
#else
template<typename T>
constexpr inline bool isValidCapacityForVector(size_t capacity) { return capacity <= (std::numeric_limits<unsigned>::max() >> 1) / sizeof(T); }
#endif

template<typename Collection> struct CopyOrMoveToVectorResult;

Expand Down
6 changes: 6 additions & 0 deletions Source/WTF/wtf/text/StringImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,12 @@ inline constexpr bool StringImpl::isValidLength(size_t length)
return length <= max;
}

#if USE(BUN_JSC_ADDITIONS)
// The UTF-8 converters size a Vector<char16_t> by the length of their input. This fails to compile if a merge
// takes the halved limit of 310668@main for isValidCapacityForVector again.
static_assert(isValidCapacityForVector<char16_t>(StringImpl::MaxLength));
#endif

template<typename T> constexpr size_t StringImpl::tailOffset()
{
return roundUpToMultipleOf<alignof(T)>(offsetof(StringImpl, m_hashAndFlags) + sizeof(StringImpl::m_hashAndFlags));
Expand Down
Loading