aboutsummaryrefslogtreecommitdiffstats
path: root/src/3rdparty/masm/yarr/YarrInterpreter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/masm/yarr/YarrInterpreter.cpp')
-rw-r--r--src/3rdparty/masm/yarr/YarrInterpreter.cpp43
1 files changed, 28 insertions, 15 deletions
diff --git a/src/3rdparty/masm/yarr/YarrInterpreter.cpp b/src/3rdparty/masm/yarr/YarrInterpreter.cpp
index 4d3652fcbc..cdcd16af64 100644
--- a/src/3rdparty/masm/yarr/YarrInterpreter.cpp
+++ b/src/3rdparty/masm/yarr/YarrInterpreter.cpp
@@ -32,12 +32,12 @@
#include "Yarr.h"
#include "YarrCanonicalize.h"
#include <wtf/BumpPointerAllocator.h>
+#include <wtf/CheckedArithmetic.h>
#include <wtf/DataLog.h>
+#include <wtf/StdLibExtras.h>
#include <wtf/text/CString.h>
#include <wtf/text/WTFString.h>
-using namespace WTF;
-
namespace JSC { namespace Yarr {
template<typename CharType>
@@ -67,17 +67,23 @@ public:
struct DisjunctionContext
{
- DisjunctionContext()
- : term(0)
- {
- }
+ DisjunctionContext() = default;
void* operator new(size_t, void* where)
{
return where;
}
- int term;
+ static size_t allocationSize(unsigned numberOfFrames)
+ {
+ static_assert(alignof(DisjunctionContext) <= sizeof(void*), "");
+ size_t rawSize = (sizeof(DisjunctionContext) - sizeof(uintptr_t) + Checked<size_t>(numberOfFrames) * sizeof(uintptr_t)).unsafeGet();
+ size_t roundedSize = WTF::roundUpToMultipleOf<sizeof(void*)>(rawSize);
+ RELEASE_ASSERT(roundedSize >= rawSize);
+ return roundedSize;
+ }
+
+ int term { 0 };
unsigned matchBegin;
unsigned matchEnd;
uintptr_t frame[1];
@@ -85,7 +91,7 @@ public:
DisjunctionContext* allocDisjunctionContext(ByteDisjunction* disjunction)
{
- size_t size = sizeof(DisjunctionContext) - sizeof(uintptr_t) + disjunction->m_frameSize * sizeof(uintptr_t);
+ size_t size = DisjunctionContext::allocationSize(disjunction->m_frameSize);
allocatorPool = allocatorPool->ensureCapacity(size);
RELEASE_ASSERT(allocatorPool);
return new (allocatorPool->alloc(size)) DisjunctionContext();
@@ -99,7 +105,6 @@ public:
struct ParenthesesDisjunctionContext
{
ParenthesesDisjunctionContext(unsigned* output, ByteTerm& term)
- : next(0)
{
unsigned firstSubpatternId = term.atom.subpatternId;
unsigned numNestedSubpatterns = term.atom.parenthesesDisjunction->m_numSubpatterns;
@@ -125,16 +130,25 @@ public:
DisjunctionContext* getDisjunctionContext(ByteTerm& term)
{
- return reinterpret_cast<DisjunctionContext*>(&(subpatternBackup[term.atom.parenthesesDisjunction->m_numSubpatterns << 1]));
+ return bitwise_cast<DisjunctionContext*>(bitwise_cast<uintptr_t>(this) + allocationSize(term.atom.parenthesesDisjunction->m_numSubpatterns));
}
- ParenthesesDisjunctionContext* next;
+ static size_t allocationSize(unsigned numberOfSubpatterns)
+ {
+ static_assert(alignof(ParenthesesDisjunctionContext) <= sizeof(void*), "");
+ size_t rawSize = (sizeof(ParenthesesDisjunctionContext) - sizeof(unsigned) + (Checked<size_t>(numberOfSubpatterns) * 2U) * sizeof(unsigned)).unsafeGet();
+ size_t roundedSize = WTF::roundUpToMultipleOf<sizeof(void*)>(rawSize);
+ RELEASE_ASSERT(roundedSize >= rawSize);
+ return roundedSize;
+ }
+
+ ParenthesesDisjunctionContext* next { nullptr };
unsigned subpatternBackup[1];
};
ParenthesesDisjunctionContext* allocParenthesesDisjunctionContext(ByteDisjunction* disjunction, unsigned* output, ByteTerm& term)
{
- 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);
+ size_t size = (Checked<size_t>(ParenthesesDisjunctionContext::allocationSize(term.atom.parenthesesDisjunction->m_numSubpatterns)) + DisjunctionContext::allocationSize(disjunction->m_frameSize)).unsafeGet();
allocatorPool = allocatorPool->ensureCapacity(size);
RELEASE_ASSERT(allocatorPool);
return new (allocatorPool->alloc(size)) ParenthesesDisjunctionContext(output, term);
@@ -1630,7 +1644,6 @@ public:
, unicode(pattern->unicode())
, output(output)
, input(input, start, length, pattern->unicode())
- , allocatorPool(0)
, startOffset(start)
, remainingMatchCount(matchLimit)
{
@@ -1641,7 +1654,7 @@ private:
bool unicode;
unsigned* output;
InputStream input;
- BumpPointerPool* allocatorPool;
+ WTF::BumpPointerPool* allocatorPool { nullptr };
unsigned startOffset;
unsigned remainingMatchCount;
};
@@ -1740,7 +1753,7 @@ public:
void atomParenthesesOnceBegin(unsigned subpatternId, bool capture, unsigned inputPosition, unsigned frameLocation, unsigned alternativeFrameLocation)
{
- unsigned beginTerm = m_bodyDisjunction->terms.size();
+ int beginTerm = m_bodyDisjunction->terms.size();
m_bodyDisjunction->terms.append(ByteTerm(ByteTerm::TypeParenthesesSubpatternOnceBegin, subpatternId, capture, false, inputPosition));
m_bodyDisjunction->terms[m_bodyDisjunction->terms.size() - 1].frameLocation = frameLocation;