/ Check-in [12f5b8c9]
Login

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

Overview
Comment:Have test_multiplex.c add a second nul-terminator byte to the strings that it passes to the xOpen method of the underlying VFS, in case that VFS passes the string to sqlite3_uri_parameter() or similar.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:12f5b8c9c9a15bd9e6aabdc708d4e869ff918e76
User & Date: dan 2012-01-09 11:37:34
Context
2012-01-09
13:41
Make sure the multiplexor does not create unnecessary overflow files. check-in: 12386197 user: drh tags: trunk
11:37
Have test_multiplex.c add a second nul-terminator byte to the strings that it passes to the xOpen method of the underlying VFS, in case that VFS passes the string to sqlite3_uri_parameter() or similar. check-in: 12f5b8c9 user: dan tags: trunk
2012-01-08
22:18
Fix typos in commands. Combine the ExpandBlob and expandBlob macros into one. check-in: fc9179e1 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to src/test_multiplex.c.

   216    216     while( *z2 ){ z2++; }
   217    217     return 0x3fffffff & (int)(z2 - z);
   218    218   }
   219    219   
   220    220   /*
   221    221   ** Generate the file-name for chunk iChunk of the group with base name
   222    222   ** zBase. The file-name is written to buffer zOut before returning. Buffer
   223         -** zOut must be allocated by the caller so that it is at least (nBase+4)
          223  +** zOut must be allocated by the caller so that it is at least (nBase+5)
   224    224   ** bytes in size, where nBase is the length of zBase, not including the
   225    225   ** nul-terminator.
          226  +**
          227  +** If iChunk is 0 (or 400 - the number for the first journal file chunk),
          228  +** the output is a copy of the input string. Otherwise, if 
          229  +** SQLITE_ENABLE_8_3_NAMES is not defined or the input buffer does not contain
          230  +** a "." character, then the output is a copy of the input string with the 
          231  +** three-digit zero-padded decimal representation if iChunk appended to it. 
          232  +** For example:
          233  +**
          234  +**   zBase="test.db", iChunk=4  ->  zOut="test.db004"
          235  +**
          236  +** Or, if SQLITE_ENABLE_8_3_NAMES is defined and the input buffer contains
          237  +** a "." character, then everything after the "." is replaced by the 
          238  +** three-digit representation of iChunk.
          239  +**
          240  +**   zBase="test.db", iChunk=4  ->  zOut="test.004"
          241  +**
          242  +** The output buffer string is terminated by 2 0x00 bytes. This makes it safe
          243  +** to pass to sqlite3_uri_parameter() and similar.
   226    244   */
   227    245   static void multiplexFilename(
   228    246     const char *zBase,              /* Filename for chunk 0 */
   229    247     int nBase,                      /* Size of zBase in bytes (without \0) */
   230    248     int flags,                      /* Flags used to open file */
   231    249     int iChunk,                     /* Chunk to generate filename for */
   232    250     char *zOut                      /* Buffer to write generated name to */
   233    251   ){
   234         -  memcpy(zOut, zBase, nBase+1);
   235         -  if( iChunk!=0 && iChunk!=SQLITE_MULTIPLEX_JOURNAL_8_3_OFFSET ){
   236    252       int n = nBase;
          253  +  memcpy(zOut, zBase, n+1);
          254  +  if( iChunk!=0 && iChunk!=SQLITE_MULTIPLEX_JOURNAL_8_3_OFFSET ){
   237    255   #ifdef SQLITE_ENABLE_8_3_NAMES
   238    256       int i;
   239    257       for(i=n-1; i>0 && i>=n-4 && zOut[i]!='.'; i--){}
   240    258       if( i>=n-4 ) n = i+1;
   241    259       if( flags & SQLITE_OPEN_MAIN_JOURNAL ){
   242    260         /* The extensions on overflow files for main databases are 001, 002,
   243    261          ** 003 and so forth.  To avoid name collisions, add 400 to the 
   244    262          ** extensions of journal files so that they are 401, 402, 403, ....
   245    263          */
   246    264         iChunk += SQLITE_MULTIPLEX_JOURNAL_8_3_OFFSET;
   247    265       }
   248    266   #endif
   249    267       sqlite3_snprintf(4,&zOut[n],"%03d",iChunk);
          268  +    n += 3;
   250    269     }
          270  +
          271  +  assert( zOut[n]=='\0' );
          272  +  zOut[n+1] = '\0';
   251    273   }
   252    274   
   253    275   /* Compute the filename for the iChunk-th chunk
   254    276   */
   255    277   static int multiplexSubFilename(multiplexGroup *pGroup, int iChunk){
   256    278     if( iChunk>=pGroup->nReal ){
   257    279       struct multiplexReal *p;
................................................................................
   262    284       memset(&p[pGroup->nReal], 0, sizeof(p[0])*(iChunk+1-pGroup->nReal));
   263    285       pGroup->aReal = p;
   264    286       pGroup->nReal = iChunk+1;
   265    287     }
   266    288     if( pGroup->zName && pGroup->aReal[iChunk].z==0 ){
   267    289       char *z;
   268    290       int n = pGroup->nName;
   269         -    pGroup->aReal[iChunk].z = z = sqlite3_malloc( n+4 );
          291  +    pGroup->aReal[iChunk].z = z = sqlite3_malloc( n+5 );
   270    292       if( z==0 ){
   271    293         return SQLITE_NOMEM;
   272    294       }
   273    295       multiplexFilename(pGroup->zName, pGroup->nName, pGroup->flags, iChunk, z);
   274    296     }
   275    297     return SQLITE_OK;
   276    298   }
................................................................................
   607    629     rc = pOrigVfs->xDelete(pOrigVfs, zName, syncDir);
   608    630     if( rc==SQLITE_OK ){
   609    631       /* If the main chunk was deleted successfully, also delete any subsequent
   610    632       ** chunks - starting with the last (highest numbered). 
   611    633       */
   612    634       int nName = strlen(zName);
   613    635       char *z;
   614         -    z = sqlite3_malloc(nName + 4);
          636  +    z = sqlite3_malloc(nName + 5);
   615    637       if( z==0 ){
   616    638         rc = SQLITE_IOERR_NOMEM;
   617    639       }else{
   618    640         int iChunk = 0;
   619    641         int bExists;
   620    642         do{
   621    643           multiplexFilename(zName, nName, SQLITE_OPEN_MAIN_JOURNAL, ++iChunk, z);

Changes to test/permutations.test.

   138    138     test_set $allquicktests -exclude *malloc* *ioerr* *fault*
   139    139   ]
   140    140   
   141    141   test_suite "valgrind" -prefix "" -description {
   142    142     Run the "veryquick" test suite with a couple of multi-process tests (that
   143    143     fail under valgrind) omitted.
   144    144   } -files [
   145         -  test_set $allquicktests -exclude *malloc* *ioerr* *fault*
          145  +  test_set $allquicktests -exclude *malloc* *ioerr* *fault* wal.test
   146    146   ] -initialize {
   147    147     set ::G(valgrind) 1
   148    148   } -shutdown {
   149    149     unset -nocomplain ::G(valgrind)
   150    150   }
   151    151   
   152    152   test_suite "quick" -prefix "" -description {