/ Check-in [fdef2a92]
Login

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

Overview
Comment:Add ALWAYS() macros on results of sqlite3_aggregate_context() calls in xInverse() implements, since they can never fail.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:fdef2a921d451c66ca535021d08af3ec1ab53283da2d2979378a799fd8731ef9
User & Date: drh 2018-07-07 19:47:21
Context
2018-07-07
20:13
Fix an LSM problem caused by using the same cursor for equality and range scans. check-in: f05bead3 user: dan tags: trunk
19:47
Add ALWAYS() macros on results of sqlite3_aggregate_context() calls in xInverse() implements, since they can never fail. check-in: fdef2a92 user: drh tags: trunk
19:36
Add an assert() to help verify that OP_AggInverse is never called on an accumulator that has not previously been processed by OP_AggStep. check-in: 42138891 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/misc/json1.c.

  1844   1844     sqlite3_value **argv
  1845   1845   ){
  1846   1846     int i;
  1847   1847     int inStr = 0;
  1848   1848     char *z;
  1849   1849     JsonString *pStr;
  1850   1850     pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
  1851         -  if( !pStr ) return;
         1851  +  /* pStr is always non-NULL since jsonArrayStep() or jsonObjectStep() will
         1852  +  ** always have been called to initalize it */
         1853  +  if( NEVER(!pStr) ) return;
  1852   1854     z = pStr->zBuf;
  1853   1855     for(i=1; z[i]!=',' || inStr; i++){
  1854   1856       assert( i<pStr->nUsed );
  1855   1857       if( z[i]=='"' ){
  1856   1858         inStr = !inStr;
  1857   1859       }else if( z[i]=='\\' ){
  1858   1860         i++;

Changes to src/func.c.

  1517   1517   static void sumInverse(sqlite3_context *context, int argc, sqlite3_value**argv){
  1518   1518     SumCtx *p;
  1519   1519     int type;
  1520   1520     assert( argc==1 );
  1521   1521     UNUSED_PARAMETER(argc);
  1522   1522     p = sqlite3_aggregate_context(context, sizeof(*p));
  1523   1523     type = sqlite3_value_numeric_type(argv[0]);
  1524         -  if( p && type!=SQLITE_NULL ){
         1524  +  /* p is always non-NULL because sumStep() will have been called first
         1525  +  ** to initialize it */
         1526  +  if( ALWAYS(p) && type!=SQLITE_NULL ){
  1525   1527       p->cnt--;
  1526   1528       if( type==SQLITE_INTEGER ){
  1527   1529         i64 v = sqlite3_value_int64(argv[0]);
  1528   1530         p->rSum -= v;
  1529   1531         if( (p->approx|p->overflow)==0 && sqlite3AddInt64(&p->iSum, -1*v) ){
  1530   1532           p->overflow = 1;
  1531   1533         }
................................................................................
  1601   1603     p = sqlite3_aggregate_context(context, 0);
  1602   1604     sqlite3_result_int64(context, p ? p->n : 0);
  1603   1605   }
  1604   1606   #ifndef SQLITE_OMIT_WINDOWFUNC
  1605   1607   static void countInverse(sqlite3_context *ctx, int argc, sqlite3_value **argv){
  1606   1608     CountCtx *p;
  1607   1609     p = sqlite3_aggregate_context(ctx, sizeof(*p));
  1608         -  if( (argc==0 || SQLITE_NULL!=sqlite3_value_type(argv[0])) && p ){
         1610  +  /* p is always non-NULL since countStep() will have been called first */
         1611  +  if( (argc==0 || SQLITE_NULL!=sqlite3_value_type(argv[0])) && ALWAYS(p) ){
  1609   1612       p->n--;
  1610   1613   #ifdef SQLITE_DEBUG
  1611   1614       p->bInverse = 1;
  1612   1615   #endif
  1613   1616     }
  1614   1617   }   
  1615   1618   #else
................................................................................
  1720   1723     sqlite3_value **argv
  1721   1724   ){
  1722   1725     int n;
  1723   1726     assert( argc==1 || argc==2 );
  1724   1727     StrAccum *pAccum;
  1725   1728     if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
  1726   1729     pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum));
  1727         -  if( pAccum ){
         1730  +  /* pAccum is always non-NULL since groupConcatStep() will have always
         1731  +  ** run frist to initialize it */
         1732  +  if( ALWAYS(pAccum) ){
  1728   1733       n = sqlite3_value_bytes(argv[0]);
  1729   1734       if( argc==2 ){
  1730   1735         n += sqlite3_value_bytes(argv[1]);
  1731   1736       }else{
  1732   1737         n++;
  1733   1738       }
  1734   1739       if( n>=pAccum->nChar ){