Changeset 108858 in webkit for trunk/Source/JavaScriptCore/yarr


Ignore:
Timestamp:
Feb 24, 2012, 3:55:01 PM (13 years ago)
Author:
[email protected]
Message:

ASSERT(position < 0) in JSC::Yarr::Interpreter::InputStream::readChecked
https://bugs.webkit.org/show_bug.cgi?id=73728

Reviewed by Gavin Barraclough.

Source/JavaScriptCore:

Fixed the mixing of signed and unsigned character indeces in YARR
interpreter.

  • runtime/RegExp.cpp:

(JSC::RegExp::match): Added code to check for match longer than 231 and
return no match after resetting the offsets.

  • yarr/YarrInterpreter.cpp: Changed to use unsigned for all character index

handling except when matching back references.
(JSC::Yarr::Interpreter::InputStream::readChecked):
(JSC::Yarr::Interpreter::InputStream::checkInput):
(JSC::Yarr::Interpreter::InputStream::uncheckInput):
(JSC::Yarr::Interpreter::InputStream::atStart):
(JSC::Yarr::Interpreter::InputStream::atEnd):
(JSC::Yarr::Interpreter::InputStream::isAvailableInput):
(JSC::Yarr::Interpreter::checkCharacter):
(JSC::Yarr::Interpreter::checkCasedCharacter):
(JSC::Yarr::Interpreter::checkCharacterClass):
(JSC::Yarr::Interpreter::tryConsumeBackReference):
(JSC::Yarr::Interpreter::matchAssertionBOL):
(JSC::Yarr::Interpreter::matchAssertionWordBoundary):
(JSC::Yarr::Interpreter::backtrackPatternCharacter):
(JSC::Yarr::Interpreter::backtrackPatternCasedCharacter):
(JSC::Yarr::Interpreter::matchCharacterClass):
(JSC::Yarr::Interpreter::backtrackCharacterClass):
(JSC::Yarr::Interpreter::matchParenthesesOnceBegin):
(JSC::Yarr::Interpreter::matchDisjunction):
(JSC::Yarr::Interpreter::interpret):
(JSC::Yarr::ByteCompiler::assertionBOL):
(JSC::Yarr::ByteCompiler::assertionEOL):
(JSC::Yarr::ByteCompiler::assertionWordBoundary):
(JSC::Yarr::ByteCompiler::atomPatternCharacter):
(JSC::Yarr::ByteCompiler::atomCharacterClass):
(JSC::Yarr::ByteCompiler::atomBackReference):
(JSC::Yarr::ByteCompiler::atomParenthesesOnceBegin):
(JSC::Yarr::ByteCompiler::atomParenthesesTerminalBegin):
(JSC::Yarr::ByteCompiler::atomParenthesesSubpatternBegin):
(JSC::Yarr::ByteCompiler::atomParentheticalAssertionEnd):
(JSC::Yarr::ByteCompiler::emitDisjunction):

  • yarr/YarrInterpreter.h:

Source/WebCore:

No new tests, refactored usage of JSC::Yarr interpreter.
Should be covered by existing tests.

Changed WebCore callers of JSC::Yarr:Interpreter::interpret() to match the
new signature with unsigned offsets.

  • inspector/ContentSearchUtils.cpp:

(WebCore::ContentSearchUtils::findMagicComment):

  • platform/text/RegularExpression.cpp:

(WebCore::RegularExpression::match):

LayoutTests:

Updated test for change. Test is from defect.

  • fast/regex/overflow-expected.txt:
  • fast/regex/script-tests/overflow.js:
Location:
trunk/Source/JavaScriptCore/yarr
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/yarr/Yarr.h

    r104900 r108858  
    4444
    4545static const unsigned quantifyInfinite = UINT_MAX;
     46static const unsigned offsetNoMatch = (unsigned)-1;
    4647
    4748// The below limit restricts the number of "recursive" match calls in order to
     
    6465
    6566JS_EXPORT_PRIVATE PassOwnPtr<BytecodePattern> byteCompile(YarrPattern&, BumpPointerAllocator*);
    66 JS_EXPORT_PRIVATE int interpret(BytecodePattern*, const UString& input, unsigned start, unsigned length, int* output);
     67JS_EXPORT_PRIVATE unsigned interpret(BytecodePattern*, const UString& input, unsigned start, unsigned length, unsigned* output);
    6768
    6869} } // namespace JSC::Yarr
  • trunk/Source/JavaScriptCore/yarr/YarrInterpreter.cpp

    r107499 r108858  
    122122    struct ParenthesesDisjunctionContext
    123123    {
    124         ParenthesesDisjunctionContext(int* output, ByteTerm& term)
     124        ParenthesesDisjunctionContext(unsigned* output, ByteTerm& term)
    125125            : next(0)
    126126        {
     
    130130            for (unsigned i = 0; i < (numNestedSubpatterns << 1); ++i) {
    131131                subpatternBackup[i] = output[(firstSubpatternId << 1) + i];
    132                 output[(firstSubpatternId << 1) + i] = -1;
     132                output[(firstSubpatternId << 1) + i] = offsetNoMatch;
    133133            }
    134134
     
    141141        }
    142142
    143         void restoreOutput(int* output, unsigned firstSubpatternId, unsigned numNestedSubpatterns)
     143        void restoreOutput(unsigned* output, unsigned firstSubpatternId, unsigned numNestedSubpatterns)
    144144        {
    145145            for (unsigned i = 0; i < (numNestedSubpatterns << 1); ++i)
     
    153153
    154154        ParenthesesDisjunctionContext* next;
    155         int subpatternBackup[1];
     155        unsigned subpatternBackup[1];
    156156    };
    157157
    158     ParenthesesDisjunctionContext* allocParenthesesDisjunctionContext(ByteDisjunction* disjunction, int* output, ByteTerm& term)
    159     {
    160         size_t size = sizeof(ParenthesesDisjunctionContext) - sizeof(int) + (term.atom.parenthesesDisjunction->m_numSubpatterns << 1) * sizeof(int) + sizeof(DisjunctionContext) - sizeof(uintptr_t) + disjunction->m_frameSize * sizeof(uintptr_t);
     158    ParenthesesDisjunctionContext* allocParenthesesDisjunctionContext(ByteDisjunction* disjunction, unsigned* output, ByteTerm& term)
     159    {
     160        size_t size = sizeof(ParenthesesDisjunctionContext) - sizeof(unsigned) + (term.atom.parenthesesDisjunction->m_numSubpatterns << 1) * sizeof(unsigned) + sizeof(DisjunctionContext) - sizeof(uintptr_t) + disjunction->m_frameSize * sizeof(uintptr_t);
    161161        allocatorPool = allocatorPool->ensureCapacity(size);
    162162        if (!allocatorPool)
     
    250250        }
    251251
    252         int readChecked(int position)
    253         {
    254             ASSERT(position < 0);
    255             ASSERT(static_cast<unsigned>(-position) <= pos);
    256             unsigned p = pos + position;
     252        int readChecked(unsigned negativePositionOffest)
     253        {
     254            if (pos < negativePositionOffest)
     255                CRASH();
     256            unsigned p = pos - negativePositionOffest;
    257257            ASSERT(p < length);
    258258            return input[p];
     
    298298        }
    299299
    300         bool checkInput(int count)
    301         {
    302             if ((pos + count) <= length) {
     300        bool checkInput(unsigned count)
     301        {
     302            if (((pos + count) <= length) && ((pos + count) >= pos)) {
    303303                pos += count;
    304304                return true;
     
    307307        }
    308308
    309         void uncheckInput(int count)
    310         {
     309        void uncheckInput(unsigned count)
     310        {
     311            if (pos < count)
     312                CRASH();
    311313            pos -= count;
    312314        }
    313315
    314         bool atStart(int position)
    315         {
    316             return (pos + position) == 0;
    317         }
    318 
    319         bool atEnd(int position)
    320         {
    321             return (pos + position) == length;
    322         }
    323 
    324         bool isNotAvailableInput(int position)
    325         {
    326             return (pos + position) > length;
     316        bool atStart(unsigned negativePositionOffest)
     317        {
     318            return pos == negativePositionOffest;
     319        }
     320
     321        bool atEnd(unsigned negativePositionOffest)
     322        {
     323            if (pos < negativePositionOffest)
     324                CRASH();
     325            return (pos - negativePositionOffest) == length;
     326        }
     327
     328        bool isAvailableInput(unsigned offset)
     329        {
     330            return (((pos + offset) <= length) && ((pos + offset) >= pos));
    327331        }
    328332
     
    354358    }
    355359
    356     bool checkCharacter(int testChar, int inputPosition)
    357     {
    358         return testChar == input.readChecked(inputPosition);
    359     }
    360 
    361     bool checkCasedCharacter(int loChar, int hiChar, int inputPosition)
    362     {
    363         int ch = input.readChecked(inputPosition);
     360    bool checkCharacter(int testChar, unsigned negativeInputOffset)
     361    {
     362        return testChar == input.readChecked(negativeInputOffset);
     363    }
     364
     365    bool checkCasedCharacter(int loChar, int hiChar, unsigned negativeInputOffset)
     366    {
     367        int ch = input.readChecked(negativeInputOffset);
    364368        return (loChar == ch) || (hiChar == ch);
    365369    }
    366370
    367     bool checkCharacterClass(CharacterClass* characterClass, bool invert, int inputPosition)
    368     {
    369         bool match = testCharacterClass(characterClass, input.readChecked(inputPosition));
     371    bool checkCharacterClass(CharacterClass* characterClass, bool invert, unsigned negativeInputOffset)
     372    {
     373        bool match = testCharacterClass(characterClass, input.readChecked(negativeInputOffset));
    370374        return invert ? !match : match;
    371375    }
    372376
    373     bool tryConsumeBackReference(int matchBegin, int matchEnd, int inputOffset)
    374     {
    375         int matchSize = matchEnd - matchBegin;
     377    bool tryConsumeBackReference(int matchBegin, int matchEnd, unsigned negativeInputOffset)
     378    {
     379        unsigned matchSize = (unsigned)(matchEnd - matchBegin);
    376380
    377381        if (!input.checkInput(matchSize))
     
    379383
    380384        if (pattern->m_ignoreCase) {
    381             for (int i = 0; i < matchSize; ++i) {
     385            for (unsigned i = 0; i < matchSize; ++i) {
    382386                int ch = input.reread(matchBegin + i);
    383387
     
    385389                int hi = Unicode::toUpper(ch);
    386390
    387                 if ((lo != hi) ? (!checkCasedCharacter(lo, hi, inputOffset - matchSize + i)) : (!checkCharacter(ch, inputOffset - matchSize + i))) {
     391                if ((lo != hi) ? (!checkCasedCharacter(lo, hi, negativeInputOffset + matchSize - i)) : (!checkCharacter(ch, negativeInputOffset + matchSize - i))) {
    388392                    input.uncheckInput(matchSize);
    389393                    return false;
     
    391395            }
    392396        } else {
    393             for (int i = 0; i < matchSize; ++i) {
    394                 if (!checkCharacter(input.reread(matchBegin + i), inputOffset - matchSize + i)) {
     397            for (unsigned i = 0; i < matchSize; ++i) {
     398                if (!checkCharacter(input.reread(matchBegin + i), negativeInputOffset + matchSize - i)) {
    395399                    input.uncheckInput(matchSize);
    396400                    return false;
     
    404408    bool matchAssertionBOL(ByteTerm& term)
    405409    {
    406         return (input.atStart(term.inputPosition)) || (pattern->m_multiline && testCharacterClass(pattern->newlineCharacterClass, input.readChecked(term.inputPosition - 1)));
     410        return (input.atStart(term.inputPosition)) || (pattern->m_multiline && testCharacterClass(pattern->newlineCharacterClass, input.readChecked(term.inputPosition + 1)));
    407411    }
    408412
     
    417421    bool matchAssertionWordBoundary(ByteTerm& term)
    418422    {
    419         bool prevIsWordchar = !input.atStart(term.inputPosition) && testCharacterClass(pattern->wordcharCharacterClass, input.readChecked(term.inputPosition - 1));
     423        bool prevIsWordchar = !input.atStart(term.inputPosition) && testCharacterClass(pattern->wordcharCharacterClass, input.readChecked(term.inputPosition + 1));
    420424        bool readIsWordchar;
    421425        if (term.inputPosition)
     
    447451            if ((backTrack->matchAmount < term.atom.quantityCount) && input.checkInput(1)) {
    448452                ++backTrack->matchAmount;
    449                 if (checkCharacter(term.atom.patternCharacter, term.inputPosition - 1))
     453                if (checkCharacter(term.atom.patternCharacter, term.inputPosition + 1))
    450454                    return true;
    451455            }
     
    476480            if ((backTrack->matchAmount < term.atom.quantityCount) && input.checkInput(1)) {
    477481                ++backTrack->matchAmount;
    478                 if (checkCasedCharacter(term.atom.casedCharacter.lo, term.atom.casedCharacter.hi, term.inputPosition - 1))
     482                if (checkCasedCharacter(term.atom.casedCharacter.lo, term.atom.casedCharacter.hi, term.inputPosition + 1))
    479483                    return true;
    480484            }
     
    494498        case QuantifierFixedCount: {
    495499            for (unsigned matchAmount = 0; matchAmount < term.atom.quantityCount; ++matchAmount) {
    496                 if (!checkCharacterClass(term.atom.characterClass, term.invert(), term.inputPosition + matchAmount))
     500                if (!checkCharacterClass(term.atom.characterClass, term.invert(), term.inputPosition - matchAmount))
    497501                    return false;
    498502            }
     
    503507            unsigned matchAmount = 0;
    504508            while ((matchAmount < term.atom.quantityCount) && input.checkInput(1)) {
    505                 if (!checkCharacterClass(term.atom.characterClass, term.invert(), term.inputPosition - 1)) {
     509                if (!checkCharacterClass(term.atom.characterClass, term.invert(), term.inputPosition + 1)) {
    506510                    input.uncheckInput(1);
    507511                    break;
     
    543547            if ((backTrack->matchAmount < term.atom.quantityCount) && input.checkInput(1)) {
    544548                ++backTrack->matchAmount;
    545                 if (checkCharacterClass(term.atom.characterClass, term.invert(), term.inputPosition - 1))
     549                if (checkCharacterClass(term.atom.characterClass, term.invert(), term.inputPosition + 1))
    546550                    return true;
    547551            }
     
    558562        BackTrackInfoBackReference* backTrack = reinterpret_cast<BackTrackInfoBackReference*>(context->frame + term.frameLocation);
    559563
    560         int matchBegin = output[(term.atom.subpatternId << 1)];
    561         int matchEnd = output[(term.atom.subpatternId << 1) + 1];
     564        unsigned matchBegin = output[(term.atom.subpatternId << 1)];
     565        unsigned matchEnd = output[(term.atom.subpatternId << 1) + 1];
    562566
    563567        // If the end position of the referenced match hasn't set yet then the backreference in the same parentheses where it references to that.
    564568        // In this case the result of match is empty string like when it references to a parentheses with zero-width match.
    565569        // Eg.: /(a\1)/
    566         if (matchEnd == -1)
     570        if (matchEnd == offsetNoMatch)
    567571            return true;
    568572
    569         if (matchBegin == -1)
     573        if (matchBegin == offsetNoMatch)
    570574            return true;
    571575
     
    610614        BackTrackInfoBackReference* backTrack = reinterpret_cast<BackTrackInfoBackReference*>(context->frame + term.frameLocation);
    611615
    612         int matchBegin = output[(term.atom.subpatternId << 1)];
    613         int matchEnd = output[(term.atom.subpatternId << 1) + 1];
    614 
    615         if (matchBegin == -1)
     616        unsigned matchBegin = output[(term.atom.subpatternId << 1)];
     617        unsigned matchEnd = output[(term.atom.subpatternId << 1) + 1];
     618
     619        if (matchBegin == offsetNoMatch)
    616620            return false;
    617621
     
    705709        if (term.capture()) {
    706710            unsigned subpatternId = term.atom.subpatternId;
    707             output[(subpatternId << 1)] = input.getPos() + term.inputPosition;
     711            output[(subpatternId << 1)] = input.getPos() - term.inputPosition;
    708712        }
    709713
     
    737741        if (term.capture()) {
    738742            unsigned subpatternId = term.atom.subpatternId;
    739             output[(subpatternId << 1)] = -1;
    740             output[(subpatternId << 1) + 1] = -1;
     743            output[(subpatternId << 1)] = offsetNoMatch;
     744            output[(subpatternId << 1) + 1] = offsetNoMatch;
    741745        }
    742746
     
    11951199        case ByteTerm::TypePatternCharacterFixed: {
    11961200            for (unsigned matchAmount = 0; matchAmount < currentTerm().atom.quantityCount; ++matchAmount) {
    1197                 if (!checkCharacter(currentTerm().atom.patternCharacter, currentTerm().inputPosition + matchAmount))
     1201                if (!checkCharacter(currentTerm().atom.patternCharacter, currentTerm().inputPosition - matchAmount))
    11981202                    BACKTRACK();
    11991203            }
     
    12041208            unsigned matchAmount = 0;
    12051209            while ((matchAmount < currentTerm().atom.quantityCount) && input.checkInput(1)) {
    1206                 if (!checkCharacter(currentTerm().atom.patternCharacter, currentTerm().inputPosition - 1)) {
     1210                if (!checkCharacter(currentTerm().atom.patternCharacter, currentTerm().inputPosition + 1)) {
    12071211                    input.uncheckInput(1);
    12081212                    break;
     
    12231227        case ByteTerm::TypePatternCasedCharacterFixed: {
    12241228            for (unsigned matchAmount = 0; matchAmount < currentTerm().atom.quantityCount; ++matchAmount) {
    1225                 if (!checkCasedCharacter(currentTerm().atom.casedCharacter.lo, currentTerm().atom.casedCharacter.hi, currentTerm().inputPosition + matchAmount))
     1229                if (!checkCasedCharacter(currentTerm().atom.casedCharacter.lo, currentTerm().atom.casedCharacter.hi, currentTerm().inputPosition - matchAmount))
    12261230                    BACKTRACK();
    12271231            }
     
    12321236            unsigned matchAmount = 0;
    12331237            while ((matchAmount < currentTerm().atom.quantityCount) && input.checkInput(1)) {
    1234                 if (!checkCasedCharacter(currentTerm().atom.casedCharacter.lo, currentTerm().atom.casedCharacter.hi, currentTerm().inputPosition - 1)) {
     1238                if (!checkCasedCharacter(currentTerm().atom.casedCharacter.lo, currentTerm().atom.casedCharacter.hi, currentTerm().inputPosition + 1)) {
    12351239                    input.uncheckInput(1);
    12361240                    break;
     
    14501454    }
    14511455
    1452     int interpret()
    1453     {
    1454         if (input.isNotAvailableInput(0))
    1455             return -1;
     1456    unsigned interpret()
     1457    {
     1458        if (!input.isAvailableInput(0))
     1459            return offsetNoMatch;
    14561460
    14571461        for (unsigned i = 0; i < pattern->m_body->m_numSubpatterns + 1; ++i)
    1458             output[i << 1] = -1;
     1462            output[i << 1] = offsetNoMatch;
    14591463
    14601464        allocatorPool = pattern->m_allocator->startAllocator();
     
    14741478        pattern->m_allocator->stopAllocator();
    14751479
    1476         ASSERT((result == JSRegExpMatch) == (output[0] != -1));
     1480        ASSERT((result == JSRegExpMatch) == (output[0] != offsetNoMatch));
    14771481        return output[0];
    14781482    }
    14791483
    1480     Interpreter(BytecodePattern* pattern, int* output, const UString input, unsigned start, unsigned length)
     1484    Interpreter(BytecodePattern* pattern, unsigned* output, const UString input, unsigned start, unsigned length)
    14811485        : pattern(pattern)
    14821486        , output(output)
     
    14891493private:
    14901494    BytecodePattern* pattern;
    1491     int* output;
     1495    unsigned* output;
    14921496    InputStream input;
    14931497    BumpPointerPool* allocatorPool;
     
    15341538    }
    15351539   
    1536     void assertionBOL(int inputPosition)
     1540    void assertionBOL(unsigned inputPosition)
    15371541    {
    15381542        m_bodyDisjunction->terms.append(ByteTerm::BOL(inputPosition));
    15391543    }
    15401544
    1541     void assertionEOL(int inputPosition)
     1545    void assertionEOL(unsigned inputPosition)
    15421546    {
    15431547        m_bodyDisjunction->terms.append(ByteTerm::EOL(inputPosition));
    15441548    }
    15451549
    1546     void assertionWordBoundary(bool invert, int inputPosition)
     1550    void assertionWordBoundary(bool invert, unsigned inputPosition)
    15471551    {
    15481552        m_bodyDisjunction->terms.append(ByteTerm::WordBoundary(invert, inputPosition));
    15491553    }
    15501554
    1551     void atomPatternCharacter(UChar ch, int inputPosition, unsigned frameLocation, Checked<unsigned> quantityCount, QuantifierType quantityType)
     1555    void atomPatternCharacter(UChar ch, unsigned inputPosition, unsigned frameLocation, Checked<unsigned> quantityCount, QuantifierType quantityType)
    15521556    {
    15531557        if (m_pattern.m_ignoreCase) {
     
    15641568    }
    15651569
    1566     void atomCharacterClass(CharacterClass* characterClass, bool invert, int inputPosition, unsigned frameLocation, Checked<unsigned> quantityCount, QuantifierType quantityType)
     1570    void atomCharacterClass(CharacterClass* characterClass, bool invert, unsigned inputPosition, unsigned frameLocation, Checked<unsigned> quantityCount, QuantifierType quantityType)
    15671571    {
    15681572        m_bodyDisjunction->terms.append(ByteTerm(characterClass, invert, inputPosition));
     
    15731577    }
    15741578
    1575     void atomBackReference(unsigned subpatternId, int inputPosition, unsigned frameLocation, Checked<unsigned> quantityCount, QuantifierType quantityType)
     1579    void atomBackReference(unsigned subpatternId, unsigned inputPosition, unsigned frameLocation, Checked<unsigned> quantityCount, QuantifierType quantityType)
    15761580    {
    15771581        ASSERT(subpatternId);
     
    15841588    }
    15851589
    1586     void atomParenthesesOnceBegin(unsigned subpatternId, bool capture, int inputPosition, unsigned frameLocation, unsigned alternativeFrameLocation)
     1590    void atomParenthesesOnceBegin(unsigned subpatternId, bool capture, unsigned inputPosition, unsigned frameLocation, unsigned alternativeFrameLocation)
    15871591    {
    15881592        int beginTerm = m_bodyDisjunction->terms.size();
     
    15971601    }
    15981602
    1599     void atomParenthesesTerminalBegin(unsigned subpatternId, bool capture, int inputPosition, unsigned frameLocation, unsigned alternativeFrameLocation)
     1603    void atomParenthesesTerminalBegin(unsigned subpatternId, bool capture, unsigned inputPosition, unsigned frameLocation, unsigned alternativeFrameLocation)
    16001604    {
    16011605        int beginTerm = m_bodyDisjunction->terms.size();
     
    16101614    }
    16111615
    1612     void atomParenthesesSubpatternBegin(unsigned subpatternId, bool capture, int inputPosition, unsigned frameLocation, unsigned alternativeFrameLocation)
     1616    void atomParenthesesSubpatternBegin(unsigned subpatternId, bool capture, unsigned inputPosition, unsigned frameLocation, unsigned alternativeFrameLocation)
    16131617    {
    16141618        // Errrk! - this is a little crazy, we initially generate as a TypeParenthesesSubpatternOnceBegin,
     
    16401644    }
    16411645
    1642     void atomParentheticalAssertionEnd(int inputPosition, unsigned frameLocation, Checked<unsigned> quantityCount, QuantifierType quantityType)
     1646    void atomParentheticalAssertionEnd(unsigned inputPosition, unsigned frameLocation, Checked<unsigned> quantityCount, QuantifierType quantityType)
    16431647    {
    16441648        unsigned beginTerm = popParenthesesStack();
     
    18721876                switch (term.type) {
    18731877                case PatternTerm::TypeAssertionBOL:
    1874                     assertionBOL(term.inputPosition - currentCountAlreadyChecked);
     1878                    assertionBOL(currentCountAlreadyChecked - term.inputPosition);
    18751879                    break;
    18761880
    18771881                case PatternTerm::TypeAssertionEOL:
    1878                     assertionEOL(term.inputPosition - currentCountAlreadyChecked);
     1882                    assertionEOL(currentCountAlreadyChecked - term.inputPosition);
    18791883                    break;
    18801884
    18811885                case PatternTerm::TypeAssertionWordBoundary:
    1882                     assertionWordBoundary(term.invert(), term.inputPosition - currentCountAlreadyChecked);
     1886                    assertionWordBoundary(term.invert(), currentCountAlreadyChecked - term.inputPosition);
    18831887                    break;
    18841888
    18851889                case PatternTerm::TypePatternCharacter:
    1886                     atomPatternCharacter(term.patternCharacter, term.inputPosition - currentCountAlreadyChecked, term.frameLocation, term.quantityCount, term.quantityType);
     1890                    atomPatternCharacter(term.patternCharacter, currentCountAlreadyChecked - term.inputPosition, term.frameLocation, term.quantityCount, term.quantityType);
    18871891                    break;
    18881892
    18891893                case PatternTerm::TypeCharacterClass:
    1890                     atomCharacterClass(term.characterClass, term.invert(), term.inputPosition - currentCountAlreadyChecked, term.frameLocation, term.quantityCount, term.quantityType);
     1894                    atomCharacterClass(term.characterClass, term.invert(), currentCountAlreadyChecked- term.inputPosition, term.frameLocation, term.quantityCount, term.quantityType);
    18911895                    break;
    18921896
    18931897                case PatternTerm::TypeBackReference:
    1894                     atomBackReference(term.backReferenceSubpatternId, term.inputPosition - currentCountAlreadyChecked, term.frameLocation, term.quantityCount, term.quantityType);
     1898                    atomBackReference(term.backReferenceSubpatternId, currentCountAlreadyChecked - term.inputPosition, term.frameLocation, term.quantityCount, term.quantityType);
    18951899                        break;
    18961900
     
    19081912                            alternativeFrameLocation += YarrStackSpaceForBackTrackInfoParenthesesOnce;
    19091913                        unsigned delegateEndInputOffset = term.inputPosition - currentCountAlreadyChecked;
    1910                         atomParenthesesOnceBegin(term.parentheses.subpatternId, term.capture(), delegateEndInputOffset - disjunctionAlreadyCheckedCount, term.frameLocation, alternativeFrameLocation);
     1914                        atomParenthesesOnceBegin(term.parentheses.subpatternId, term.capture(), disjunctionAlreadyCheckedCount - delegateEndInputOffset, term.frameLocation, alternativeFrameLocation);
    19111915                        emitDisjunction(term.parentheses.disjunction, currentCountAlreadyChecked, disjunctionAlreadyCheckedCount);
    19121916                        atomParenthesesOnceEnd(delegateEndInputOffset, term.frameLocation, term.quantityCount, term.quantityType);
    19131917                    } else if (term.parentheses.isTerminal) {
    19141918                        unsigned delegateEndInputOffset = term.inputPosition - currentCountAlreadyChecked;
    1915                         atomParenthesesTerminalBegin(term.parentheses.subpatternId, term.capture(), delegateEndInputOffset - disjunctionAlreadyCheckedCount, term.frameLocation, term.frameLocation + YarrStackSpaceForBackTrackInfoParenthesesOnce);
     1919                        atomParenthesesTerminalBegin(term.parentheses.subpatternId, term.capture(), disjunctionAlreadyCheckedCount - delegateEndInputOffset, term.frameLocation, term.frameLocation + YarrStackSpaceForBackTrackInfoParenthesesOnce);
    19161920                        emitDisjunction(term.parentheses.disjunction, currentCountAlreadyChecked, disjunctionAlreadyCheckedCount);
    19171921                        atomParenthesesTerminalEnd(delegateEndInputOffset, term.frameLocation, term.quantityCount, term.quantityType);
    19181922                    } else {
    19191923                        unsigned delegateEndInputOffset = term.inputPosition - currentCountAlreadyChecked;
    1920                         atomParenthesesSubpatternBegin(term.parentheses.subpatternId, term.capture(), delegateEndInputOffset - disjunctionAlreadyCheckedCount, term.frameLocation, 0);
     1924                        atomParenthesesSubpatternBegin(term.parentheses.subpatternId, term.capture(), disjunctionAlreadyCheckedCount - delegateEndInputOffset, term.frameLocation, 0);
    19211925                        emitDisjunction(term.parentheses.disjunction, currentCountAlreadyChecked, 0);
    19221926                        atomParenthesesSubpatternEnd(term.parentheses.lastSubpatternId, delegateEndInputOffset, term.frameLocation, term.quantityCount, term.quantityType, term.parentheses.disjunction->m_callFrameSize);
     
    19681972}
    19691973
    1970 int interpret(BytecodePattern* bytecode, const UString& input, unsigned start, unsigned length, int* output)
     1974unsigned interpret(BytecodePattern* bytecode, const UString& input, unsigned start, unsigned length, unsigned* output)
    19711975{
    19721976    return Interpreter(bytecode, output, input, start, length).interpret();
  • trunk/Source/JavaScriptCore/yarr/YarrInterpreter.h

    r95901 r108858  
    106106    bool m_capture : 1;
    107107    bool m_invert : 1;
    108     int inputPosition;
     108    unsigned inputPosition;
    109109
    110110    ByteTerm(UChar ch, int inputPos, unsigned frameLocation, Checked<unsigned> quantityCount, QuantifierType quantityType)
Note: See TracChangeset for help on using the changeset viewer.