/ Check-in [9eea3670]
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 a subtle bug in the remember UDF of the kvtest.exe utility program.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 9eea3670e77e2f831b7c00ae2d65a5583f9cad626d9ab286f92582ef29ecd4e3
User & Date: drh 2017-06-05 19:20:35
Context
2017-06-06
18:20
Add the SQLITE_DEFAULT_ROWEST compile-time option for changing the estimated number of rows in tables that lack sqlite_stat1 entries. check-in: 234ede26 user: drh tags: trunk
2017-06-05
19:20
Fix a subtle bug in the remember UDF of the kvtest.exe utility program. check-in: 9eea3670 user: drh tags: trunk
16:33
Fix a bug in test_fs.c that occurs when the first component of a path contains a GLOB or LIKE escape character. check-in: 73c70590 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/kvtest.c.

   539    539     zFN = sqlite3_mprintf("%s/00/00/00.extra---------------------", zDir);
   540    540     if( zFN==0 ){
   541    541       fatalError("malloc failed\n");
   542    542     }
   543    543     zTail = zFN + nFN + 1;
   544    544     while( sqlite3_step(pStmt)==SQLITE_ROW ){
   545    545       int iKey = sqlite3_column_int(pStmt, 0);
   546         -    int nData = sqlite3_column_bytes(pStmt, 1);
          546  +    sqlite3_int64 nData = sqlite3_column_bytes(pStmt, 1);
   547    547       const void *pData = sqlite3_column_blob(pStmt, 1);
   548    548       FILE *out;
   549    549       if( ePathType==PATH_DIR ){
   550    550         sqlite3_snprintf(20, zTail, "%06d", iKey);
   551    551       }else{
   552    552         sqlite3_snprintf(20, zTail, "%02d", iKey/10000);
   553    553         kvtest_mkdir(zFN);
................................................................................
   583    583   ** For convenience, a nul-terminator byte is always appended to the data read
   584    584   ** from the file before the buffer is returned. This byte is not included in
   585    585   ** the final value of (*pnByte), if applicable.
   586    586   **
   587    587   ** NULL is returned if any error is encountered. The final value of *pnByte
   588    588   ** is undefined in this case.
   589    589   */
   590         -static unsigned char *readFile(const char *zName, int *pnByte){
          590  +static unsigned char *readFile(const char *zName, sqlite3_int64 *pnByte){
   591    591     FILE *in;               /* FILE from which to read content of zName */
   592    592     sqlite3_int64 nIn;      /* Size of zName in bytes */
   593    593     size_t nRead;           /* Number of bytes actually read */
   594    594     unsigned char *pBuf;    /* Content read from disk */
   595    595   
   596    596     nIn = fileSize(zName);
   597    597     if( nIn<0 ) return 0;
................................................................................
   601    601     if( pBuf==0 ) return 0;
   602    602     nRead = fread(pBuf, (size_t)nIn, 1, in);
   603    603     fclose(in);
   604    604     if( nRead!=1 ){
   605    605       sqlite3_free(pBuf);
   606    606       return 0;
   607    607     }
   608         -  if( pnByte ) *pnByte = (int)nIn;
          608  +  if( pnByte ) *pnByte = nIn;
   609    609     return pBuf;
   610    610   }
   611    611   
   612    612   /*
   613    613   ** Overwrite a file with randomness.  Do not change the size of the
   614    614   ** file.
   615    615   */
   616         -static void updateFile(const char *zName, int *pnByte, int doFsync){
          616  +static void updateFile(const char *zName, sqlite3_int64 *pnByte, int doFsync){
   617    617     FILE *out;              /* FILE from which to read content of zName */
   618    618     sqlite3_int64 sz;       /* Size of zName in bytes */
   619    619     size_t nWritten;        /* Number of bytes actually read */
   620    620     unsigned char *pBuf;    /* Content to store on disk */
   621    621     const char *zMode = "wb";   /* Mode for fopen() */
   622    622   
   623    623     sz = fileSize(zName);
   624    624     if( sz<0 ){
   625    625       fatalError("No such file: \"%s\"", zName);
   626    626     }
   627         -  *pnByte = (int)sz;
          627  +  *pnByte = sz;
   628    628     if( sz==0 ) return;
   629    629     pBuf = sqlite3_malloc64( sz );
   630    630     if( pBuf==0 ){
   631    631       fatalError("Cannot allocate %lld bytes\n", sz);
   632    632     }
   633    633     sqlite3_randomness((int)sz, pBuf); 
   634    634   #if defined(_WIN32)
................................................................................
   816    816     int noCheckpoint = 0;       /* Omit the checkpoint in WAL mode */
   817    817     sqlite3 *db = 0;            /* Database connection */
   818    818     sqlite3_stmt *pStmt = 0;    /* Prepared statement for SQL access */
   819    819     sqlite3_blob *pBlob = 0;    /* Handle for incremental Blob I/O */
   820    820     sqlite3_int64 tmStart;      /* Start time */
   821    821     sqlite3_int64 tmElapsed;    /* Elapsed time */
   822    822     int mmapSize = 0;           /* --mmap N argument */
   823         -  int nData = 0;              /* Bytes of data */
          823  +  sqlite3_int64 nData = 0;    /* Bytes of data */
   824    824     sqlite3_int64 nTotal = 0;   /* Total data read */
   825    825     unsigned char *pData = 0;   /* Content of the blob */
   826         -  int nAlloc = 0;             /* Space allocated for pData[] */
          826  +  sqlite3_int64 nAlloc = 0;   /* Space allocated for pData[] */
   827    827     const char *zJMode = 0;     /* Journal mode */
   828    828     
   829    829   
   830    830     assert( strcmp(argv[1],"run")==0 );
   831    831     assert( argc>=3 );
   832    832     zDb = argv[2];
   833    833     eType = pathType(zDb);
................................................................................
  1009   1009         }else{
  1010   1010           rc = sqlite3_blob_reopen(pBlob, iKey);
  1011   1011         }
  1012   1012         if( rc==SQLITE_OK ){
  1013   1013           nData = sqlite3_blob_bytes(pBlob);
  1014   1014           if( nAlloc<nData+1 ){
  1015   1015             nAlloc = nData+100;
  1016         -          pData = sqlite3_realloc(pData, nAlloc);
         1016  +          pData = sqlite3_realloc64(pData, nAlloc);
  1017   1017           }
  1018   1018           if( pData==0 ) fatalError("cannot allocate %d bytes", nData+1);
  1019   1019           if( isUpdateTest ){
  1020   1020             sqlite3_randomness((int)nData, pData);
  1021         -          rc = sqlite3_blob_write(pBlob, pData, nData, 0);
         1021  +          rc = sqlite3_blob_write(pBlob, pData, (int)nData, 0);
  1022   1022             if( rc!=SQLITE_OK ){
  1023   1023               fatalError("could not write the blob at %d: %s", iKey,
  1024   1024                         sqlite3_errmsg(db));
  1025   1025             }
  1026   1026           }else{
  1027         -          rc = sqlite3_blob_read(pBlob, pData, nData, 0);
         1027  +          rc = sqlite3_blob_read(pBlob, pData, (int)nData, 0);
  1028   1028             if( rc!=SQLITE_OK ){
  1029   1029               fatalError("could not read the blob at %d: %s", iKey,
  1030   1030                         sqlite3_errmsg(db));
  1031   1031             }
  1032   1032           }
  1033   1033         }
  1034   1034       }else{