/ Check-in [e9bf275c]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix compiler warnings in fts5 code.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e9bf275cd969eca6fb41384d3637528d6a19f819
User & Date: dan 2015-07-16 20:17:57
Context
2015-07-17
01:16
Avoid a harmless compiler warning. check-in: 2288842b user: drh tags: trunk
2015-07-16
20:24
Merge trunk changes, including fixes for compiler warnings in fts5 code, with this branch. check-in: 7190d79b user: dan tags: fts5-btree-index
20:17
Fix compiler warnings in fts5 code. check-in: e9bf275c user: dan tags: trunk
18:37
Fix harmless compiler warnings. check-in: 9a592cf9 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts5/fts5_expr.c.

    79     79   ** A phrase. One or more terms that must appear in a contiguous sequence
    80     80   ** within a document for it to match.
    81     81   */
    82     82   struct Fts5ExprPhrase {
    83     83     Fts5ExprNode *pNode;            /* FTS5_STRING node this phrase is part of */
    84     84     Fts5Buffer poslist;             /* Current position list */
    85     85     int nTerm;                      /* Number of entries in aTerm[] */
    86         -  Fts5ExprTerm aTerm[0];          /* Terms that make up this phrase */
           86  +  Fts5ExprTerm aTerm[1];          /* Terms that make up this phrase */
    87     87   };
    88     88   
    89     89   /*
    90     90   ** If a NEAR() clump may only match a specific set of columns, then
    91     91   ** Fts5ExprNearset.pColset points to an object of the following type.
    92     92   ** Each entry in the aiCol[] array
    93     93   */
................................................................................
   100    100   ** One or more phrases that must appear within a certain token distance of
   101    101   ** each other within each matching document.
   102    102   */
   103    103   struct Fts5ExprNearset {
   104    104     int nNear;                      /* NEAR parameter */
   105    105     Fts5ExprColset *pColset;        /* Columns to search (NULL -> all columns) */
   106    106     int nPhrase;                    /* Number of entries in aPhrase[] array */
   107         -  Fts5ExprPhrase *apPhrase[0];    /* Array of phrase pointers */
          107  +  Fts5ExprPhrase *apPhrase[1];    /* Array of phrase pointers */
   108    108   };
   109    109   
   110    110   
   111    111   /*
   112    112   ** Parse context.
   113    113   */
   114    114   struct Fts5Parse {

Changes to ext/fts5/fts5_hash.c.

    62     62     int iSzPoslist;                 /* Offset of space for 4-byte poslist size */
    63     63     int nData;                      /* Total bytes of data (incl. structure) */
    64     64     u8 bDel;                        /* Set delete-flag @ iSzPoslist */
    65     65   
    66     66     int iCol;                       /* Column of last value written */
    67     67     int iPos;                       /* Position of last value written */
    68     68     i64 iRowid;                     /* Rowid of last value written */
    69         -  char zKey[0];                   /* Nul-terminated entry key */
           69  +  char zKey[8];                   /* Nul-terminated entry key */
    70     70   };
           71  +
           72  +/*
           73  +** Size of Fts5HashEntry without the zKey[] array.
           74  +*/
           75  +#define FTS5_HASHENTRYSIZE (sizeof(Fts5HashEntry)-8)
           76  +
           77  +
    71     78   
    72     79   /*
    73     80   ** Allocate a new hash table.
    74     81   */
    75     82   int sqlite3Fts5HashNew(Fts5Hash **ppNew, int *pnByte){
    76     83     int rc = SQLITE_OK;
    77     84     Fts5Hash *pNew;
................................................................................
   216    223       ){
   217    224         break;
   218    225       }
   219    226     }
   220    227   
   221    228     /* If an existing hash entry cannot be found, create a new one. */
   222    229     if( p==0 ){
   223         -    int nByte = sizeof(Fts5HashEntry) + (nToken+1) + 1 + 64;
          230  +    int nByte = FTS5_HASHENTRYSIZE + (nToken+1) + 1 + 64;
   224    231       if( nByte<128 ) nByte = 128;
   225    232   
   226    233       if( (pHash->nEntry*2)>=pHash->nSlot ){
   227    234         int rc = fts5HashResize(pHash);
   228    235         if( rc!=SQLITE_OK ) return rc;
   229    236         iHash = fts5HashKey2(pHash->nSlot, bByte, pToken, nToken);
   230    237       }
   231    238   
   232    239       p = (Fts5HashEntry*)sqlite3_malloc(nByte);
   233    240       if( !p ) return SQLITE_NOMEM;
   234         -    memset(p, 0, sizeof(Fts5HashEntry));
          241  +    memset(p, 0, FTS5_HASHENTRYSIZE);
   235    242       p->nAlloc = nByte;
   236    243       p->zKey[0] = bByte;
   237    244       memcpy(&p->zKey[1], pToken, nToken);
   238    245       assert( iHash==fts5HashKey(pHash->nSlot, p->zKey, nToken+1) );
   239    246       p->zKey[nToken+1] = '\0';
   240         -    p->nData = nToken+1 + 1 + sizeof(Fts5HashEntry);
          247  +    p->nData = nToken+1 + 1 + FTS5_HASHENTRYSIZE;
   241    248       p->nData += sqlite3Fts5PutVarint(&((u8*)p)[p->nData], iRowid);
   242    249       p->iSzPoslist = p->nData;
   243    250       p->nData += 1;
   244    251       p->iRowid = iRowid;
   245    252       p->pHashNext = pHash->aSlot[iHash];
   246    253       pHash->aSlot[iHash] = p;
   247    254       pHash->nEntry++;
................................................................................
   413    420     for(p=pHash->aSlot[iHash]; p; p=p->pHashNext){
   414    421       if( memcmp(p->zKey, pTerm, nTerm)==0 && p->zKey[nTerm]==0 ) break;
   415    422     }
   416    423   
   417    424     if( p ){
   418    425       fts5HashAddPoslistSize(p);
   419    426       *ppDoclist = (const u8*)&p->zKey[nTerm+1];
   420         -    *pnDoclist = p->nData - (sizeof(*p) + nTerm + 1);
          427  +    *pnDoclist = p->nData - (FTS5_HASHENTRYSIZE + nTerm + 1);
   421    428     }else{
   422    429       *ppDoclist = 0;
   423    430       *pnDoclist = 0;
   424    431     }
   425    432   
   426    433     return SQLITE_OK;
   427    434   }
................................................................................
   450    457   ){
   451    458     Fts5HashEntry *p;
   452    459     if( (p = pHash->pScan) ){
   453    460       int nTerm = strlen(p->zKey);
   454    461       fts5HashAddPoslistSize(p);
   455    462       *pzTerm = p->zKey;
   456    463       *ppDoclist = (const u8*)&p->zKey[nTerm+1];
   457         -    *pnDoclist = p->nData - (sizeof(*p) + nTerm + 1);
          464  +    *pnDoclist = p->nData - (FTS5_HASHENTRYSIZE + nTerm + 1);
   458    465     }else{
   459    466       *pzTerm = 0;
   460    467       *ppDoclist = 0;
   461    468       *pnDoclist = 0;
   462    469     }
   463    470   }
   464    471   

Changes to ext/fts5/fts5_index.c.

   364    364     Fts5StructureSegment *aSeg;     /* Array of segments. aSeg[0] is oldest. */
   365    365   };
   366    366   struct Fts5Structure {
   367    367     int nRef;                       /* Object reference count */
   368    368     u64 nWriteCounter;              /* Total leaves written to level 0 */
   369    369     int nSegment;                   /* Total segments in this structure */
   370    370     int nLevel;                     /* Number of levels in this index */
   371         -  Fts5StructureLevel aLevel[0];   /* Array of nLevel level objects */
          371  +  Fts5StructureLevel aLevel[1];   /* Array of nLevel level objects */
   372    372   };
   373    373   
   374    374   /*
   375    375   ** An object of type Fts5SegWriter is used to write to segments.
   376    376   */
   377    377   struct Fts5PageWriter {
   378    378     int pgno;                       /* Page number for this page */
................................................................................
   925    925   
   926    926     /* Read the total number of levels and segments from the start of the
   927    927     ** structure record.  */
   928    928     i += fts5GetVarint32(&pData[i], nLevel);
   929    929     i += fts5GetVarint32(&pData[i], nSegment);
   930    930     nByte = (
   931    931         sizeof(Fts5Structure) +                    /* Main structure */
   932         -      sizeof(Fts5StructureLevel) * (nLevel)      /* aLevel[] array */
          932  +      sizeof(Fts5StructureLevel) * (nLevel-1)    /* aLevel[] array */
   933    933     );
   934    934     pRet = (Fts5Structure*)sqlite3Fts5MallocZero(&rc, nByte);
   935    935   
   936    936     if( pRet ){
   937    937       pRet->nRef = 1;
   938    938       pRet->nLevel = nLevel;
   939    939       pRet->nSegment = nSegment;
................................................................................
  3066   3066   ** any currently existing segment. If a free segment id cannot be found,
  3067   3067   ** SQLITE_FULL is returned.
  3068   3068   **
  3069   3069   ** If an error has already occurred, this function is a no-op. 0 is 
  3070   3070   ** returned in this case.
  3071   3071   */
  3072   3072   static int fts5AllocateSegid(Fts5Index *p, Fts5Structure *pStruct){
  3073         -  u32 iSegid = 0;
         3073  +  int iSegid = 0;
  3074   3074   
  3075   3075     if( p->rc==SQLITE_OK ){
  3076   3076       if( pStruct->nSegment>=FTS5_MAX_SEGMENT ){
  3077   3077         p->rc = SQLITE_FULL;
  3078   3078       }else{
  3079   3079         while( iSegid==0 ){
  3080   3080           int iLvl, iSeg;
  3081   3081           sqlite3_randomness(sizeof(u32), (void*)&iSegid);
  3082         -        iSegid = (iSegid % ((1 << FTS5_DATA_ID_B) - 2)) + 1;
  3083         -        assert( iSegid>0 && iSegid<=65535 );
         3082  +        iSegid = iSegid & ((1 << FTS5_DATA_ID_B)-1);
  3084   3083           for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
  3085   3084             for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
  3086   3085               if( iSegid==pStruct->aLevel[iLvl].aSeg[iSeg].iSegid ){
  3087   3086                 iSegid = 0;
  3088   3087               }
  3089   3088             }
  3090   3089           }
  3091   3090         }
  3092   3091       }
  3093   3092     }
  3094   3093   
  3095         -  return (int)iSegid;
         3094  +  return iSegid;
  3096   3095   }
  3097   3096   
  3098   3097   /*
  3099   3098   ** Discard all data currently cached in the hash-tables.
  3100   3099   */
  3101   3100   static void fts5IndexDiscardData(Fts5Index *p){
  3102   3101     assert( p->pHash || p->nPendingData==0 );

Changes to ext/fts5/fts5_main.c.

   141    141   **   byte of the position list for the corresponding phrase.
   142    142   */
   143    143   struct Fts5Sorter {
   144    144     sqlite3_stmt *pStmt;
   145    145     i64 iRowid;                     /* Current rowid */
   146    146     const u8 *aPoslist;             /* Position lists for current row */
   147    147     int nIdx;                       /* Number of entries in aIdx[] */
   148         -  int aIdx[0];                    /* Offsets into aPoslist for current row */
          148  +  int aIdx[1];                    /* Offsets into aPoslist for current row */
   149    149   };
   150    150   
   151    151   
   152    152   /*
   153    153   ** Virtual-table cursor object.
   154    154   **
   155    155   ** iSpecial:
................................................................................
   804    804     int nByte;
   805    805     int rc = SQLITE_OK;
   806    806     char *zSql;
   807    807     const char *zRank = pCsr->zRank;
   808    808     const char *zRankArgs = pCsr->zRankArgs;
   809    809     
   810    810     nPhrase = sqlite3Fts5ExprPhraseCount(pCsr->pExpr);
   811         -  nByte = sizeof(Fts5Sorter) + sizeof(int) * nPhrase;
          811  +  nByte = sizeof(Fts5Sorter) + sizeof(int) * (nPhrase-1);
   812    812     pSorter = (Fts5Sorter*)sqlite3_malloc(nByte);
   813    813     if( pSorter==0 ) return SQLITE_NOMEM;
   814    814     memset(pSorter, 0, nByte);
   815    815     pSorter->nIdx = nPhrase;
   816    816   
   817    817     /* TODO: It would be better to have some system for reusing statement
   818    818     ** handles here, rather than preparing a new one for each query. But that