Changeset 241447 in webkit
- Timestamp:
- Feb 13, 2019 11:16:36 AM (5 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r241442 r241447 1 2019-02-13 Tadeu Zagallo <tzagallo@apple.com> 2 3 VariableLengthObject::allocate<T> should initialize objects 4 https://bugs.webkit.org/show_bug.cgi?id=194534 5 6 Reviewed by Michael Saboff. 7 8 `buffer()` should not be called for empty VariableLengthObjects, but 9 these cases were not being caught due to the objects not being properly 10 initialized. Fix it so that allocate calls the constructor and fix the 11 assertion failues. 12 13 * runtime/CachedTypes.cpp: 14 (JSC::CachedObject::operator new): 15 (JSC::VariableLengthObject::allocate): 16 (JSC::CachedVector::encode): 17 (JSC::CachedVector::decode const): 18 (JSC::CachedUniquedStringImpl::decode const): 19 (JSC::CachedBitVector::encode): 20 (JSC::CachedBitVector::decode const): 21 (JSC::CachedArray::encode): 22 (JSC::CachedArray::decode const): 23 (JSC::CachedImmutableButterfly::CachedImmutableButterfly): 24 (JSC::CachedBigInt::decode const): 25 1 26 2019-02-13 Tadeu Zagallo <tzagallo@apple.com> 2 27 -
trunk/Source/JavaScriptCore/runtime/CachedTypes.cpp
r241236 r241447 307 307 class CachedObject { 308 308 WTF_MAKE_NONCOPYABLE(CachedObject<Source>); 309 WTF_FORBID_HEAP_ALLOCATION;310 309 311 310 public: 312 311 using SourceType_ = Source; 312 313 CachedObject() = default; 314 315 inline void* operator new(size_t, void* where) { return where; } 316 317 // Copied from WTF_FORBID_HEAP_ALLOCATION, since we only want to allow placement new 318 void* operator new[](size_t, void*) = delete; 319 void* operator new(size_t) = delete; 320 void operator delete(void*) = delete; 321 void* operator new[](size_t size) = delete; 322 void operator delete[](void*) = delete; 323 void* operator new(size_t, NotNullTag, void* location) = delete; 313 324 }; 314 325 … … 333 344 uint8_t* allocate(Encoder& encoder, size_t size) 334 345 { 335 if (!size)336 return nullptr;337 338 346 ptrdiff_t offsetOffset = encoder.offsetOf(&m_offset); 339 347 auto result = encoder.malloc(size); … … 346 354 { 347 355 uint8_t* result = allocate(encoder, sizeof(T) * size); 348 return reinterpret_cast<T*>(result);356 return new (result) T(); 349 357 } 350 358 … … 464 472 { 465 473 m_size = vector.size(); 474 if (!m_size) 475 return; 466 476 T* buffer = this->template allocate<T>(encoder, m_size); 467 477 for (unsigned i = 0; i < m_size; ++i) … … 472 482 void decode(Decoder& decoder, Vector<SourceType<T>, InlineCapacity, OverflowHandler>& vector, Args... args) const 473 483 { 484 if (!m_size) 485 return; 474 486 vector.resizeToFit(m_size); 475 487 const T* buffer = this->template buffer<T>(); … … 571 583 return AtomicStringImpl::add(buffer, m_length).leakRef(); 572 584 573 if (!m_length)574 return &SymbolImpl::createNullSymbol().leakRef();575 576 585 Identifier ident = Identifier::fromString(&decoder.vm(), buffer, m_length); 577 586 String str = decoder.vm().propertyNames->lookUpPrivateName(ident); … … 581 590 }; 582 591 592 if (!m_length) { 593 if (m_isSymbol) 594 return &SymbolImpl::createNullSymbol().leakRef(); 595 return AtomicStringImpl::add("").leakRef(); 596 } 597 583 598 if (m_is8Bit) 584 599 return create(this->buffer<LChar>()); … … 741 756 { 742 757 m_size = bitVector.size(); 758 if (!m_size) 759 return; 743 760 uint8_t* buffer = this->allocate(encoder, m_size); 744 761 memcpy(buffer, bitVector.bits(), m_size); … … 747 764 void decode(Decoder&, BitVector& bitVector) const 748 765 { 766 if (!m_size) 767 return; 749 768 bitVector.ensureSize(m_size); 750 769 memcpy(bitVector.bits(), this->buffer(), m_size); … … 861 880 void encode(Encoder& encoder, const Source* array, unsigned size) 862 881 { 882 if (!size) 883 return; 863 884 T* dst = this->template allocate<T>(encoder, size); 864 885 for (unsigned i = 0; i < size; ++i) … … 869 890 void decode(Decoder& decoder, Source* array, unsigned size, Args... args) const 870 891 { 892 if (!size) 893 return; 871 894 const T* buffer = this->template buffer<T>(); 872 895 for (unsigned i = 0; i < size; ++i) … … 949 972 class CachedImmutableButterfly : public CachedObject<JSImmutableButterfly> { 950 973 public: 974 CachedImmutableButterfly() 975 : m_cachedDoubles() 976 { 977 } 978 951 979 void encode(Encoder& encoder, JSImmutableButterfly& immutableButterfly) 952 980 { … … 1038 1066 JSBigInt* bigInt = JSBigInt::createWithLengthUnchecked(decoder.vm(), m_length); 1039 1067 bigInt->setSign(m_sign); 1040 memcpy(bigInt->dataStorage(), this->buffer(), sizeof(JSBigInt::Digit) * m_length); 1068 if (m_length) 1069 memcpy(bigInt->dataStorage(), this->buffer(), sizeof(JSBigInt::Digit) * m_length); 1041 1070 return bigInt; 1042 1071 }
Note: See TracChangeset
for help on using the changeset viewer.