/ Check-in [d2800394]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Fix harmless compiler warnings in the zonefile extension seen with MSVC.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | zonefile
Files: files | file ages | folders
SHA3-256: d28003941ceca7fb707fcdb09bf8b00a6c1b728956e018d7ecfb6852d7dd469b
User & Date: mistachkin 2018-02-23 14:00:38
Context
2018-02-23
14:02
Fix a problem with DROP TABLE statements on zonefile virtual tables. check-in: d2ed6910 user: dan tags: zonefile
14:00
Fix harmless compiler warnings in the zonefile extension seen with MSVC. check-in: d2800394 user: mistachkin tags: zonefile
13:58
Avoid running a test case that requires zstd in non-SQLITE_HAVE_ZSTD builds. check-in: d716dff4 user: dan tags: zonefile
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Makefile.msc.

  1490   1490     $(TOP)\ext\misc\amatch.c \
  1491   1491     $(TOP)\ext\misc\carray.c \
  1492   1492     $(TOP)\ext\misc\closure.c \
  1493   1493     $(TOP)\ext\misc\csv.c \
  1494   1494     $(TOP)\ext\misc\eval.c \
  1495   1495     $(TOP)\ext\misc\fileio.c \
  1496   1496     $(TOP)\ext\misc\fuzzer.c \
         1497  +  $(TOP)\ext\zonefile\zonefile.c \
  1497   1498     $(TOP)\ext\fts5\fts5_tcl.c \
  1498   1499     $(TOP)\ext\fts5\fts5_test_mi.c \
  1499   1500     $(TOP)\ext\fts5\fts5_test_tok.c \
  1500   1501     $(TOP)\ext\misc\ieee754.c \
  1501   1502     $(TOP)\ext\misc\mmapwarm.c \
  1502   1503     $(TOP)\ext\misc\nextchar.c \
  1503   1504     $(TOP)\ext\misc\normalize.c \

Changes to ext/zonefile/zonefile.c.

   998    998   static void zonefileAppendBlob(ZonefileBuffer *pBuf, const u8 *p, int n){
   999    999     memcpy(&pBuf->a[pBuf->n], p, n);
  1000   1000     pBuf->n += n;
  1001   1001   }
  1002   1002   
  1003   1003   static int zonefileFileWrite(FILE *pFd, const u8 *aBuf, int nBuf){
  1004   1004     size_t res = fwrite(aBuf, 1, nBuf, pFd);
  1005         -  return res!=nBuf ? SQLITE_ERROR : SQLITE_OK;
         1005  +  return res!=(size_t)nBuf ? SQLITE_ERROR : SQLITE_OK;
  1006   1006   }
  1007   1007   
  1008   1008   static int zonefileFileRead(FILE *pFd, u8 *aBuf, int nBuf, i64 iOff){
  1009         -  int rc = fseek(pFd, iOff, SEEK_SET);
         1009  +  int rc = fseek(pFd, (long)iOff, SEEK_SET);
  1010   1010     if( rc==0 ){
  1011   1011       rc = fread(aBuf, 1, nBuf, pFd);
  1012   1012       rc = (rc==nBuf) ? SQLITE_OK : SQLITE_ERROR;
  1013   1013     }
  1014   1014     return rc;
  1015   1015   }
  1016   1016   
................................................................................
  1072   1072   ** Parameter nByte is only ever non-zero when running tests. So it doesn't
  1073   1073   ** matter if this function is inefficient in those cases.
  1074   1074   */
  1075   1075   static int zonefilePad(FILE *pFd, int nByte){
  1076   1076     assert( nByte>=0 && nByte<256 );
  1077   1077     if( nByte ){
  1078   1078       int nRem = nByte;
  1079         -    u8 buf[16] = "0123456789ABCDEF";
         1079  +    u8 buf[17] = "0123456789ABCDEF";
  1080   1080       while( nRem>0 ){
  1081   1081         int n = MIN(nRem, sizeof(buf));
  1082   1082         if( zonefileFileWrite(pFd, buf, n) ) return SQLITE_ERROR;
  1083   1083         nRem -= n;
  1084   1084       }
  1085   1085     }
  1086   1086     return SQLITE_OK;
................................................................................
  1098   1098     const char *zTbl = 0;           /* Database object to read from */
  1099   1099     const char *zJson = 0;          /* JSON configuration parameters */
  1100   1100     ZonefileParam sParam;           /* Decoded JSON parameters */
  1101   1101     int nKey = 0;                   /* Number of keys in new zonefile */
  1102   1102     int nFrame = 0;                 /* Number of frames in new zonefile */
  1103   1103     sqlite3_stmt *pStmt = 0;        /* SQL used to read data from source table */
  1104   1104     FILE *pFd = 0;
  1105         -  int rc;
         1105  +  int rc = SQLITE_OK;
  1106   1106     sqlite3_value *pPrev = 0;
  1107   1107     char *zErr = 0;
  1108   1108     void *pCmp = 0;                 /* Data compressor handle */
  1109   1109     u32 iOff;
  1110   1110     ZonefileCodec *pCodec = 0;
  1111   1111   
  1112   1112     ZonefileBuffer sFrameIdx = {0, 0, 0};     /* Array of frame offsets */
................................................................................
  1291   1291       sFrameIdx.n = 0;
  1292   1292       if( rc ) goto zone_write_out;
  1293   1293     }
  1294   1294   
  1295   1295     /* Create the zonefile header in the in-memory buffer */
  1296   1296     memset(aHdr, 0, ZONEFILE_SZ_HEADER);
  1297   1297     zonefilePut32(&aHdr[0], ZONEFILE_MAGIC_NUMBER);
  1298         -  aHdr[4] = sParam.pCmpIdx->eType;
  1299         -  aHdr[5] = sParam.pCmpData->eType;
         1298  +  aHdr[4] = (u8)sParam.pCmpIdx->eType;
         1299  +  aHdr[5] = (u8)sParam.pCmpData->eType;
  1300   1300     iOff = ZONEFILE_SZ_HEADER + sFrameIdx.n + sKeyIdx.n;
  1301   1301     zonefilePut32(&aHdr[6], sDict.n ? iOff+sParam.debugExtendedHeaderSize : 0);
  1302   1302     zonefilePut32(&aHdr[10], iOff + sParam.debugExtendedHeaderSize + sDict.n);
  1303   1303     zonefilePut32(&aHdr[14], nFrame);
  1304   1304     zonefilePut32(&aHdr[18], nKey);
  1305         -  aHdr[22] = sParam.encryptionType;
         1305  +  aHdr[22] = (u8)sParam.encryptionType;
  1306   1306     aHdr[23] = 0;                   /* Encryption key index */
  1307   1307     aHdr[24] = 0;                   /* extended header version */
  1308         -  aHdr[25] = sParam.debugExtendedHeaderSize;
         1308  +  aHdr[25] = (u8)sParam.debugExtendedHeaderSize;
  1309   1309     assert( ZONEFILE_SZ_HEADER>=26 );
  1310   1310   
  1311   1311     rc = zonefileFileWrite(pFd, aHdr, ZONEFILE_SZ_HEADER);
  1312   1312     if( rc==SQLITE_OK ) rc = zonefilePad(pFd, sParam.debugExtendedHeaderSize);
  1313   1313     if( rc==SQLITE_OK ) rc = zonefileFileWrite(pFd, sFrameIdx.a, sFrameIdx.n);
  1314   1314     if( rc==SQLITE_OK ) rc = zonefileFileWrite(pFd, sKeyIdx.a, sKeyIdx.n);
  1315   1315     if( rc==SQLITE_OK ) rc = zonefileFileWrite(pFd, sDict.a, sDict.n);
................................................................................
  1550   1550   }
  1551   1551   
  1552   1552   static void zonefileJsonHeader(sqlite3_context *pCtx, const char *zFile){
  1553   1553     char *zErr = 0;
  1554   1554     FILE *pFd = zonefileFileOpen(zFile, 0, &zErr);
  1555   1555     if( pFd ){
  1556   1556       int rc;
  1557         -    ZonefileHeader hdr;
         1557  +    ZonefileHeader hdr = { 0 };
  1558   1558       u8 aBuf[ZONEFILE_SZ_HEADER];
  1559   1559   
  1560   1560       rc = zonefileFileRead(pFd, aBuf, ZONEFILE_SZ_HEADER, 0);
  1561   1561       if( rc==SQLITE_OK ){
  1562   1562         zonefileHeaderDeserialize(aBuf, &hdr);
  1563   1563       }
  1564   1564   
................................................................................
  1763   1763   
  1764   1764   
  1765   1765   static int zonefilePopulateIndex(
  1766   1766     ZonefileFilesTab *pTab,
  1767   1767     const char *zFile,
  1768   1768     i64 iFileid
  1769   1769   ){
  1770         -  ZonefileHeader hdr;
         1770  +  ZonefileHeader hdr = { 0 };
  1771   1771     int rc;
  1772   1772     FILE *pFd = zonefileFileOpen(zFile, 0, &pTab->base.zErrMsg);
  1773   1773   
  1774   1774     if( pFd==0 ){
  1775   1775       rc = SQLITE_ERROR;
  1776   1776     }else{
  1777   1777       rc = zonefileReadHeader(pFd, zFile, &hdr, &pTab->base.zErrMsg);
................................................................................
  1788   1788         rc = zonefilePrepare(pTab->db, &pTab->pInsertIdx, &pTab->base.zErrMsg,
  1789   1789             "INSERT INTO %Q.'%q_shadow_idx'(k, fileid, fofst, fsz, ofst, sz)"
  1790   1790             "VALUES(?,?,?,?,?,?)",
  1791   1791             pTab->zDb, pTab->zBase
  1792   1792         );
  1793   1793       }
  1794   1794   
  1795         -    for(i=0; i<hdr.numKeys && rc==SQLITE_OK; i++){
         1795  +    for(i=0; (u32)i<hdr.numKeys && rc==SQLITE_OK; i++){
  1796   1796         u8 *aEntry = &aKey[4*hdr.numFrames + ZONEFILE_SZ_KEYOFFSETS_ENTRY * i];
  1797   1797         int iFrame = zonefileGet32(&aEntry[8]);
  1798   1798         i64 iFrameOff = 0;          /* Offset of frame */
  1799   1799         int szFrame;                /* Compressed size of frame */
  1800   1800         i64 iOff;                   /* Offset of blob within uncompressed frame */
  1801   1801         int sz;                     /* Size of blob within uncompressed frame */
  1802   1802   
  1803   1803         szFrame = zonefileGet32(&aKey[iFrame*4]);
  1804   1804         if( iFrame>0 ){
  1805   1805           iFrameOff = zonefileGet32(&aKey[(iFrame-1)*4]);
  1806         -        szFrame -= iFrameOff;
         1806  +        szFrame -= (int)iFrameOff;
  1807   1807         }
  1808   1808         iFrameOff += hdr.byteOffsetFrames;
  1809   1809         iOff = (i64)zonefileGet32(&aEntry[12]);
  1810   1810         sz = (int)zonefileGet32(&aEntry[16]);
  1811   1811   
  1812   1812         sqlite3_bind_int64(pTab->pInsertIdx, 1, (i64)zonefileGet64(&aEntry[0]));
  1813   1813         sqlite3_bind_int64(pTab->pInsertIdx, 2, iFileid);
................................................................................
  2533   2533   static int zonefileValueReadCache(sqlite3_context *pCtx, ZonefileCsr *pCsr){
  2534   2534     int rc = SQLITE_OK;
  2535   2535     ZonefileTab *pTab = (ZonefileTab*)pCsr->base.pVtab;
  2536   2536     ZonefileFrame *pFrame = 0;
  2537   2537     i64 iFile = sqlite3_column_int64(pCsr->pSelect, 1);
  2538   2538     i64 iFrameOff = sqlite3_column_int64(pCsr->pSelect, 2);
  2539   2539     i64 iKeyOff = sqlite3_column_int64(pCsr->pSelect, 4);
  2540         -  int nKeySz = sqlite3_column_int64(pCsr->pSelect, 5);
         2540  +  int nKeySz = sqlite3_column_int(pCsr->pSelect, 5);
  2541   2541   
  2542   2542     /* Check if this frame is already in the cache. If not, read it from 
  2543   2543     ** the file.  */
  2544   2544     pFrame = zonefileCacheFind(pTab, iFile, iFrameOff);
  2545   2545     if( pFrame==0 ){
  2546   2546       const char *zFile = 0;
  2547   2547       char *zErr = 0;
  2548   2548       FILE *pFd = 0;
  2549         -    ZonefileHeader hdr;
         2549  +    ZonefileHeader hdr = { 0 };
  2550   2550       ZonefileCompress *pCmpMethod = 0;
  2551   2551       ZonefileCodec *pCodec = 0;
  2552   2552       void *pCmp = 0;
  2553   2553   
  2554   2554       /* Open the file to read the blob from */
  2555   2555       rc = zonefileGetFile(pCtx, pCsr, &zFile);
  2556   2556       if( rc==SQLITE_OK ){