Changeset 260383 in webkit
- Timestamp:
- Apr 20, 2020 12:10:00 PM (4 years ago)
- Location:
- trunk/Source/WTF
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r260366 r260383 1 2020-04-20 Darin Adler <darin@apple.com> 2 3 REGRESSION (r253987): StringImpl::adopt(Vector&&) copies only half of the characters in the Vector when copying across malloc zones 4 https://bugs.webkit.org/show_bug.cgi?id=210736 5 6 Reviewed by Yusuke Suzuki. 7 8 * wtf/text/StringImpl.cpp: 9 (WTF::StringImpl::replace): Use copyCharacters instead of memcpy. 10 11 * wtf/text/StringImpl.h: Use std::is_same_v instead of std::is_same. 12 (WTF::StringImpl::StringImpl): Use copyCharacters instead of memcpy. 13 Also drop C-style cast to cast away const. 14 (WTF::StringImpl::adopt): Don't even try to adopt across malloc zones. 15 1 16 2020-04-20 Darin Adler <darin@apple.com> 2 17 -
trunk/Source/WTF/wtf/text/StringImpl.cpp
r259773 r260383 1303 1303 auto newImpl = createUninitializedInternalNonEmpty(m_length, data); 1304 1304 1305 memcpy(data, m_data16, i * sizeof(UChar));1305 copyCharacters(data, m_data16, i); 1306 1306 for (unsigned j = i; j != m_length; ++j) { 1307 1307 UChar character = m_data16[j]; -
trunk/Source/WTF/wtf/text/StringImpl.h
r257681 r260383 893 893 : StringImplShape(s_refCountIncrement, length, static_cast<const LChar*>(nullptr), s_hashFlag8BitBuffer | StringNormal | BufferOwned) 894 894 { 895 if constexpr (std::is_same <Malloc, StringImplMalloc>::value)895 if constexpr (std::is_same_v<Malloc, StringImplMalloc>) 896 896 m_data8 = characters.leakPtr(); 897 897 else { 898 m_data8 = static_cast<const LChar*>(StringImplMalloc::malloc(length)); 899 memcpy((void*)m_data8, characters.get(), length); 898 auto data8 = static_cast<LChar*>(StringImplMalloc::malloc(length * sizeof(LChar))); 899 copyCharacters(data8, characters.get(), length); 900 m_data8 = data8; 900 901 } 901 902 … … 928 929 : StringImplShape(s_refCountIncrement, length, static_cast<const UChar*>(nullptr), StringNormal | BufferOwned) 929 930 { 930 if constexpr (std::is_same <Malloc, StringImplMalloc>::value)931 if constexpr (std::is_same_v<Malloc, StringImplMalloc>) 931 932 m_data16 = characters.leakPtr(); 932 933 else { 933 m_data16 = static_cast<const UChar*>(StringImplMalloc::malloc(length * sizeof(UChar))); 934 memcpy((void*)m_data16, characters.get(), length * sizeof(UChar)); 934 auto data16 = static_cast<UChar*>(StringImplMalloc::malloc(length * sizeof(UChar))); 935 copyCharacters(data16, characters.get(), length); 936 m_data16 = data16; 935 937 } 936 938 … … 1032 1034 inline Ref<StringImpl> StringImpl::adopt(Vector<CharacterType, inlineCapacity, OverflowHandler, minCapacity, Malloc>&& vector) 1033 1035 { 1034 if (size_t size = vector.size()) { 1035 ASSERT(vector.data()); 1036 if (size > MaxLength) 1036 if constexpr (std::is_same_v<Malloc, StringImplMalloc>) { 1037 auto length = vector.size(); 1038 if (!length) 1039 return *empty(); 1040 if (length > MaxLength) 1037 1041 CRASH(); 1038 1039 if constexpr (std::is_same<Malloc, StringImplMalloc>::value) 1040 return adoptRef(*new StringImpl(vector.releaseBuffer(), size)); 1041 else { 1042 // We have to copy between malloc zones. 1043 auto vectorBuffer = vector.releaseBuffer(); 1044 auto stringImplBuffer = MallocPtr<CharacterType, StringImplMalloc>::malloc(size); 1045 memcpy(stringImplBuffer.get(), vectorBuffer.get(), size); 1046 return adoptRef(*new StringImpl(WTFMove(stringImplBuffer), size)); 1047 } 1048 } 1049 return *empty(); 1042 return adoptRef(*new StringImpl(vector.releaseBuffer(), length)); 1043 } else 1044 return create(vector.data(), vector.size()); 1050 1045 } 1051 1046 … … 1135 1130 inline void StringImpl::copyCharacters(DestinationCharacterType* destination, const SourceCharacterType* source, unsigned numCharacters) 1136 1131 { 1137 static_assert(std::is_same <SourceCharacterType, LChar>::value || std::is_same<SourceCharacterType, UChar>::value);1138 static_assert(std::is_same <DestinationCharacterType, LChar>::value || std::is_same<DestinationCharacterType, UChar>::value);1139 if constexpr (std::is_same <SourceCharacterType, DestinationCharacterType>::value) {1132 static_assert(std::is_same_v<SourceCharacterType, LChar> || std::is_same_v<SourceCharacterType, UChar>); 1133 static_assert(std::is_same_v<DestinationCharacterType, LChar> || std::is_same_v<DestinationCharacterType, UChar>); 1134 if constexpr (std::is_same_v<SourceCharacterType, DestinationCharacterType>) { 1140 1135 if (numCharacters == 1) { 1141 1136 *destination = *source;
Note: See TracChangeset
for help on using the changeset viewer.