Index: ext/fts5/fts5_index.c ================================================================== --- ext/fts5/fts5_index.c +++ ext/fts5/fts5_index.c @@ -2130,16 +2130,37 @@ } fts5AssertNodeSeekOk(pNode, pTerm, nTerm, iPg, *pbDlidx); return iPg; } + +#define fts5IndexGetVarint32(a, iOff, nVal) { \ + nVal = a[iOff++]; \ + if( nVal & 0x80 ){ \ + iOff--; \ + iOff += fts5GetVarint32(&a[iOff], nVal); \ + } \ +} + +#define fts5IndexSkipVarint(a, iOff) { \ + int iEnd = iOff+9; \ + while( (a[iOff++] & 0x80) && iOff= search */ Fts5SegIter *pIter, /* Iterator to seek */ @@ -2166,16 +2187,11 @@ int i; int nCmp; i64 rowid; /* Figure out how many new bytes are in this term */ - - nNew = a[iOff++]; - if( nNew & 0x80 ){ - iOff--; - iOff += fts5GetVarint32(&a[iOff], nNew); - } + fts5IndexGetVarint32(a, iOff, nNew); if( nKeep> 1); + if( iOff>=n ) goto search_failed; + + /* If this is the end of the doclist, break out of the loop */ + if( a[iOff]==0x00 ){ + iOff++; + break; + } }; - if( iOff>=n ) goto search_failed; /* Read the nKeep field of the next term. */ - nKeep = a[iOff++]; - if( nKeep & 0x80 ){ - iOff--; - iOff += fts5GetVarint32(&a[iOff], nKeep); - } + fts5IndexGetVarint32(a, iOff, nKeep); } search_failed: if( bGe==0 ){ fts5DataRelease(pIter->pLeaf);