Changeset 234916 in webkit for trunk/Source/JavaScriptCore/yarr/YarrInterpreter.cpp
- Timestamp:
- Aug 16, 2018, 2:41:36 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/yarr/YarrInterpreter.cpp
r232718 r234916 33 33 #include "YarrCanonicalize.h" 34 34 #include <wtf/BumpPointerAllocator.h> 35 #include <wtf/CheckedArithmetic.h> 35 36 #include <wtf/DataLog.h> 36 37 #include <wtf/text/CString.h> … … 68 69 struct DisjunctionContext 69 70 { 70 DisjunctionContext() 71 : term(0) 72 { 73 } 71 DisjunctionContext() = default; 74 72 75 73 void* operator new(size_t, void* where) … … 78 76 } 79 77 80 int term; 78 static size_t allocationSize(unsigned numberOfFrames) 79 { 80 static_assert(alignof(DisjunctionContext) <= sizeof(void*), ""); 81 size_t rawSize = (sizeof(DisjunctionContext) - sizeof(uintptr_t) + Checked<size_t>(numberOfFrames) * sizeof(uintptr_t)).unsafeGet(); 82 size_t roundedSize = roundUpToMultipleOf<sizeof(void*)>(rawSize); 83 RELEASE_ASSERT(roundedSize >= rawSize); 84 return roundedSize; 85 } 86 87 int term { 0 }; 81 88 unsigned matchBegin; 82 89 unsigned matchEnd; … … 86 93 DisjunctionContext* allocDisjunctionContext(ByteDisjunction* disjunction) 87 94 { 88 size_t size = sizeof(DisjunctionContext) - sizeof(uintptr_t) + disjunction->m_frameSize * sizeof(uintptr_t);95 size_t size = DisjunctionContext::allocationSize(disjunction->m_frameSize); 89 96 allocatorPool = allocatorPool->ensureCapacity(size); 90 97 RELEASE_ASSERT(allocatorPool); … … 100 107 { 101 108 ParenthesesDisjunctionContext(unsigned* output, ByteTerm& term) 102 : next(0)103 109 { 104 110 unsigned firstSubpatternId = term.atom.subpatternId; … … 126 132 DisjunctionContext* getDisjunctionContext(ByteTerm& term) 127 133 { 128 return reinterpret_cast<DisjunctionContext*>(&(subpatternBackup[term.atom.parenthesesDisjunction->m_numSubpatterns << 1])); 129 } 130 131 ParenthesesDisjunctionContext* next; 134 return bitwise_cast<DisjunctionContext*>(bitwise_cast<uintptr_t>(this) + allocationSize(term.atom.parenthesesDisjunction->m_numSubpatterns)); 135 } 136 137 static size_t allocationSize(unsigned numberOfSubpatterns) 138 { 139 static_assert(alignof(ParenthesesDisjunctionContext) <= sizeof(void*), ""); 140 size_t rawSize = (sizeof(ParenthesesDisjunctionContext) - sizeof(unsigned) + (Checked<size_t>(numberOfSubpatterns) * 2U) * sizeof(unsigned)).unsafeGet(); 141 size_t roundedSize = roundUpToMultipleOf<sizeof(void*)>(rawSize); 142 RELEASE_ASSERT(roundedSize >= rawSize); 143 return roundedSize; 144 } 145 146 ParenthesesDisjunctionContext* next { nullptr }; 132 147 unsigned subpatternBackup[1]; 133 148 }; … … 135 150 ParenthesesDisjunctionContext* allocParenthesesDisjunctionContext(ByteDisjunction* disjunction, unsigned* output, ByteTerm& term) 136 151 { 137 size_t size = sizeof(ParenthesesDisjunctionContext) - sizeof(unsigned) + (term.atom.parenthesesDisjunction->m_numSubpatterns << 1) * sizeof(unsigned) + sizeof(DisjunctionContext) - sizeof(uintptr_t) + static_cast<size_t>(disjunction->m_frameSize) * sizeof(uintptr_t);152 size_t size = (Checked<size_t>(ParenthesesDisjunctionContext::allocationSize(term.atom.parenthesesDisjunction->m_numSubpatterns)) + DisjunctionContext::allocationSize(disjunction->m_frameSize)).unsafeGet(); 138 153 allocatorPool = allocatorPool->ensureCapacity(size); 139 154 RELEASE_ASSERT(allocatorPool); … … 1631 1646 , output(output) 1632 1647 , input(input, start, length, pattern->unicode()) 1633 , allocatorPool(0)1634 1648 , startOffset(start) 1635 1649 , remainingMatchCount(matchLimit) … … 1642 1656 unsigned* output; 1643 1657 InputStream input; 1644 BumpPointerPool* allocatorPool ;1658 BumpPointerPool* allocatorPool { nullptr }; 1645 1659 unsigned startOffset; 1646 1660 unsigned remainingMatchCount;
Note:
See TracChangeset
for help on using the changeset viewer.