/ Check-in [23d67af3]
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:Do not store the zero string terminator as part of the name when holding symbols in the symbol table. (CVS 6557)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 23d67af39227aeade2ea0292e1b8844eea580993
User & Date: drh 2009-04-28 13:01:09
Context
2009-04-28
15:35
Have sqlite3_create_collation() return MISUSE if passed an encoding value other than SQLITE_UTF8, SQLITE_UTF16LE, SQLITE_UTF16BE, SQLITE_UTF16 or SQLITE_UTF16_ALIGNED. (CVS 6558) check-in: 7975b6f2 user: danielk1977 tags: trunk
13:01
Do not store the zero string terminator as part of the name when holding symbols in the symbol table. (CVS 6557) check-in: 23d67af3 user: drh tags: trunk
12:08
Another fix to the same assert as in (6555). It can also fail after a malloc error. (CVS 6556) check-in: e096f90a user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

    18     18   **     CREATE INDEX
    19     19   **     DROP INDEX
    20     20   **     creating ID lists
    21     21   **     BEGIN TRANSACTION
    22     22   **     COMMIT
    23     23   **     ROLLBACK
    24     24   **
    25         -** $Id: build.c,v 1.531 2009/04/24 18:06:09 danielk1977 Exp $
           25  +** $Id: build.c,v 1.532 2009/04/28 13:01:09 drh Exp $
    26     26   */
    27     27   #include "sqliteInt.h"
    28     28   
    29     29   /*
    30     30   ** This routine is called when a new SQL statement is beginning to
    31     31   ** be parsed.  Initialize the pParse structure as needed.
    32     32   */
................................................................................
   257    257   ** See also sqlite3LocateTable().
   258    258   */
   259    259   Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
   260    260     Table *p = 0;
   261    261     int i;
   262    262     int nName;
   263    263     assert( zName!=0 );
   264         -  nName = sqlite3Strlen(db, zName) + 1;
          264  +  nName = sqlite3Strlen(db, zName);
   265    265     for(i=OMIT_TEMPDB; i<db->nDb; i++){
   266    266       int j = (i<2) ? i^1 : i;   /* Search TEMP before MAIN */
   267    267       if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue;
   268    268       p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName, nName);
   269    269       if( p ) break;
   270    270     }
   271    271     return p;
................................................................................
   319    319   ** for duplicate index names is done.)  The search order is
   320    320   ** TEMP first, then MAIN, then any auxiliary databases added
   321    321   ** using the ATTACH command.
   322    322   */
   323    323   Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){
   324    324     Index *p = 0;
   325    325     int i;
   326         -  int nName = sqlite3Strlen(db, zName)+1;
          326  +  int nName = sqlite3Strlen(db, zName);
   327    327     for(i=OMIT_TEMPDB; i<db->nDb; i++){
   328    328       int j = (i<2) ? i^1 : i;  /* Search TEMP before MAIN */
   329    329       Schema *pSchema = db->aDb[j].pSchema;
   330    330       if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue;
   331    331       assert( pSchema || (j==1 && !db->aDb[1].pBt) );
   332    332       if( pSchema ){
   333    333         p = sqlite3HashFind(&pSchema->idxHash, zName, nName);
................................................................................
   355    355   ** Unlinking from the Table must be done by the calling function.
   356    356   */
   357    357   static void sqlite3DeleteIndex(Index *p){
   358    358     Index *pOld;
   359    359     const char *zName = p->zName;
   360    360   
   361    361     pOld = sqlite3HashInsert(&p->pSchema->idxHash, zName,
   362         -                           sqlite3Strlen30(zName)+1, 0);
          362  +                           sqlite3Strlen30(zName), 0);
   363    363     assert( pOld==0 || pOld==p );
   364    364     freeIndex(p);
   365    365   }
   366    366   
   367    367   /*
   368    368   ** For the index called zIdxName which is found in the database iDb,
   369    369   ** unlike that index from its Table then remove the index from
................................................................................
   372    372   */
   373    373   void sqlite3UnlinkAndDeleteIndex(sqlite3 *db, int iDb, const char *zIdxName){
   374    374     Index *pIndex;
   375    375     int len;
   376    376     Hash *pHash = &db->aDb[iDb].pSchema->idxHash;
   377    377   
   378    378     len = sqlite3Strlen(db, zIdxName);
   379         -  pIndex = sqlite3HashInsert(pHash, zIdxName, len+1, 0);
          379  +  pIndex = sqlite3HashInsert(pHash, zIdxName, len, 0);
   380    380     if( pIndex ){
   381    381       if( pIndex->pTable->pIndex==pIndex ){
   382    382         pIndex->pTable->pIndex = pIndex->pNext;
   383    383       }else{
   384    384         Index *p;
   385    385         for(p=pIndex->pTable->pIndex; p && p->pNext!=pIndex; p=p->pNext){}
   386    386         if( p && p->pNext==pIndex ){
................................................................................
   520    520   #ifndef SQLITE_OMIT_FOREIGN_KEY
   521    521     /* Delete all foreign keys associated with this table.  The keys
   522    522     ** should have already been unlinked from the pSchema->aFKey hash table 
   523    523     */
   524    524     for(pFKey=pTable->pFKey; pFKey; pFKey=pNextFKey){
   525    525       pNextFKey = pFKey->pNextFrom;
   526    526       assert( sqlite3HashFind(&pTable->pSchema->aFKey,
   527         -                           pFKey->zTo, sqlite3Strlen30(pFKey->zTo)+1)!=pFKey );
          527  +                           pFKey->zTo, sqlite3Strlen30(pFKey->zTo))!=pFKey );
   528    528       sqlite3DbFree(db, pFKey);
   529    529     }
   530    530   #endif
   531    531   
   532    532     /* Delete the Table structure itself.
   533    533     */
   534    534     sqliteResetColumnNames(pTable);
................................................................................
   552    552     Db *pDb;
   553    553   
   554    554     assert( db!=0 );
   555    555     assert( iDb>=0 && iDb<db->nDb );
   556    556     assert( zTabName && zTabName[0] );
   557    557     pDb = &db->aDb[iDb];
   558    558     p = sqlite3HashInsert(&pDb->pSchema->tblHash, zTabName,
   559         -                        sqlite3Strlen30(zTabName)+1,0);
          559  +                        sqlite3Strlen30(zTabName),0);
   560    560     if( p ){
   561    561   #ifndef SQLITE_OMIT_FOREIGN_KEY
   562    562       for(pF1=p->pFKey; pF1; pF1=pF1->pNextFrom){
   563         -      int nTo = sqlite3Strlen30(pF1->zTo) + 1;
          563  +      int nTo = sqlite3Strlen30(pF1->zTo);
   564    564         pF2 = sqlite3HashFind(&pDb->pSchema->aFKey, pF1->zTo, nTo);
   565    565         if( pF2==pF1 ){
   566    566           sqlite3HashInsert(&pDb->pSchema->aFKey, pF1->zTo, nTo, pF1->pNextTo);
   567    567         }else{
   568    568           while( pF2 && pF2->pNextTo!=pF1 ){ pF2=pF2->pNextTo; }
   569    569           if( pF2 ){
   570    570             pF2->pNextTo = pF1->pNextTo;
................................................................................
  1684   1684     /* Add the table to the in-memory representation of the database.
  1685   1685     */
  1686   1686     if( db->init.busy && pParse->nErr==0 ){
  1687   1687       Table *pOld;
  1688   1688       FKey *pFKey; 
  1689   1689       Schema *pSchema = p->pSchema;
  1690   1690       pOld = sqlite3HashInsert(&pSchema->tblHash, p->zName,
  1691         -                             sqlite3Strlen30(p->zName)+1,p);
         1691  +                             sqlite3Strlen30(p->zName),p);
  1692   1692       if( pOld ){
  1693   1693         assert( p==pOld );  /* Malloc must have failed inside HashInsert() */
  1694   1694         db->mallocFailed = 1;
  1695   1695         return;
  1696   1696       }
  1697   1697   #ifndef SQLITE_OMIT_FOREIGN_KEY
  1698   1698       for(pFKey=p->pFKey; pFKey; pFKey=pFKey->pNextFrom){
  1699   1699         void *data;
  1700         -      int nTo = sqlite3Strlen30(pFKey->zTo) + 1;
         1700  +      int nTo = sqlite3Strlen30(pFKey->zTo);
  1701   1701         pFKey->pNextTo = sqlite3HashFind(&pSchema->aFKey, pFKey->zTo, nTo);
  1702   1702         data = sqlite3HashInsert(&pSchema->aFKey, pFKey->zTo, nTo, pFKey);
  1703   1703         if( data==(void *)pFKey ){
  1704   1704           db->mallocFailed = 1;
  1705   1705         }
  1706   1706       }
  1707   1707   #endif
................................................................................
  2738   2738   
  2739   2739     /* Link the new Index structure to its table and to the other
  2740   2740     ** in-memory database structures. 
  2741   2741     */
  2742   2742     if( db->init.busy ){
  2743   2743       Index *p;
  2744   2744       p = sqlite3HashInsert(&pIndex->pSchema->idxHash, 
  2745         -                          pIndex->zName, sqlite3Strlen30(pIndex->zName)+1,
         2745  +                          pIndex->zName, sqlite3Strlen30(pIndex->zName),
  2746   2746                             pIndex);
  2747   2747       if( p ){
  2748   2748         assert( p==pIndex );  /* Malloc must have failed */
  2749   2749         db->mallocFailed = 1;
  2750   2750         goto exit_create_index;
  2751   2751       }
  2752   2752       db->flags |= SQLITE_InternChanges;

Changes to src/hash.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This is the implementation of generic hash-tables
    13     13   ** used in SQLite.
    14     14   **
    15         -** $Id: hash.c,v 1.33 2009/01/09 01:12:28 drh Exp $
           15  +** $Id: hash.c,v 1.34 2009/04/28 13:01:09 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   #include <assert.h>
    19     19   
    20     20   /* Turn bulk memory into a hash table object by initializing the
    21     21   ** fields of the Hash structure.
    22     22   **
................................................................................
    59     59   
    60     60   /*
    61     61   ** Hash and comparison functions when the mode is SQLITE_HASH_STRING
    62     62   */
    63     63   static int strHash(const void *pKey, int nKey){
    64     64     const char *z = (const char *)pKey;
    65     65     int h = 0;
    66         -  if( nKey<=0 ) nKey = sqlite3Strlen30(z);
           66  +  assert( nKey>0 );
    67     67     while( nKey > 0  ){
    68     68       h = (h<<3) ^ h ^ sqlite3UpperToLower[(unsigned char)*z++];
    69     69       nKey--;
    70     70     }
    71     71     return h & 0x7fffffff;
    72     72   }
    73     73   static int strCompare(const void *pKey1, int n1, const void *pKey2, int n2){

Changes to src/test_async.c.

     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   **
    13         -** $Id: test_async.c,v 1.61 2009/04/25 08:39:15 danielk1977 Exp $
           13  +** $Id: test_async.c,v 1.62 2009/04/28 13:01:09 drh Exp $
    14     14   **
    15     15   ** This file contains a binding of the asynchronous IO extension interface
    16     16   ** (defined in ext/async/sqlite3async.h) to Tcl.
    17     17   */
    18     18   
    19     19   #define TCL_THREADS 
    20     20   #include <tcl.h>
................................................................................
   236    236   
   237    237     Tcl_CreateObjCommand(interp,"sqlite3async_control",testAsyncControl,0,0);
   238    238     Tcl_CreateObjCommand(interp,"sqlite3async_initialize",testAsyncInit,0,0);
   239    239     Tcl_CreateObjCommand(interp,"sqlite3async_shutdown",testAsyncShutdown,0,0);
   240    240   #endif  /* SQLITE_ENABLE_ASYNCIO */
   241    241     return TCL_OK;
   242    242   }
   243         -

Changes to src/trigger.c.

     6      6   **    May you do good and not evil.
     7      7   **    May you find forgiveness for yourself and forgive others.
     8      8   **    May you share freely, never taking more than you give.
     9      9   **
    10     10   *************************************************************************
    11     11   **
    12     12   **
    13         -** $Id: trigger.c,v 1.136 2009/04/23 13:22:44 drh Exp $
           13  +** $Id: trigger.c,v 1.137 2009/04/28 13:01:09 drh Exp $
    14     14   */
    15     15   #include "sqliteInt.h"
    16     16   
    17     17   #ifndef SQLITE_OMIT_TRIGGER
    18     18   /*
    19     19   ** Delete a linked list of TriggerStep structures.
    20     20   */
................................................................................
   281    281       Trigger *pLink = pTrig;
   282    282       Hash *pHash = &db->aDb[iDb].pSchema->trigHash;
   283    283       pTrig = sqlite3HashInsert(pHash, zName, sqlite3Strlen30(zName), pTrig);
   284    284       if( pTrig ){
   285    285         db->mallocFailed = 1;
   286    286       }else if( pLink->pSchema==pLink->pTabSchema ){
   287    287         Table *pTab;
   288         -      int n = sqlite3Strlen30(pLink->table) + 1;
          288  +      int n = sqlite3Strlen30(pLink->table);
   289    289         pTab = sqlite3HashFind(&pLink->pTabSchema->tblHash, pLink->table, n);
   290    290         assert( pTab!=0 );
   291    291         pLink->pNext = pTab->pTrigger;
   292    292         pTab->pTrigger = pLink;
   293    293       }
   294    294     }
   295    295   
................................................................................
   508    508   }
   509    509   
   510    510   /*
   511    511   ** Return a pointer to the Table structure for the table that a trigger
   512    512   ** is set on.
   513    513   */
   514    514   static Table *tableOfTrigger(Trigger *pTrigger){
   515         -  int n = sqlite3Strlen30(pTrigger->table) + 1;
          515  +  int n = sqlite3Strlen30(pTrigger->table);
   516    516     return sqlite3HashFind(&pTrigger->pTabSchema->tblHash, pTrigger->table, n);
   517    517   }
   518    518   
   519    519   
   520    520   /*
   521    521   ** Drop a trigger given a pointer to that trigger. 
   522    522   */

Changes to src/vtab.c.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used to help implement virtual tables.
    13     13   **
    14         -** $Id: vtab.c,v 1.85 2009/04/11 16:27:20 drh Exp $
           14  +** $Id: vtab.c,v 1.86 2009/04/28 13:01:09 drh Exp $
    15     15   */
    16     16   #ifndef SQLITE_OMIT_VIRTUALTABLE
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   /*
    20     20   ** The actual function that does the work of creating a new module.
    21     21   ** This function implements the sqlite3_create_module() and
................................................................................
   304    304     ** record of the table. If the module has already been registered,
   305    305     ** also call the xConnect method here.
   306    306     */
   307    307     else {
   308    308       Table *pOld;
   309    309       Schema *pSchema = pTab->pSchema;
   310    310       const char *zName = pTab->zName;
   311         -    int nName = sqlite3Strlen30(zName) + 1;
          311  +    int nName = sqlite3Strlen30(zName);
   312    312       pOld = sqlite3HashInsert(&pSchema->tblHash, zName, nName, pTab);
   313    313       if( pOld ){
   314    314         db->mallocFailed = 1;
   315    315         assert( pTab==pOld );  /* Malloc must have failed inside HashInsert() */
   316    316         return;
   317    317       }
   318    318       pSchema->db = pParse->db;