/ Check-in [5602ec95]
Login

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

Overview
Comment:Fix compiler warnings discovered while building SQLite on http://www.devio.us/.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 5602ec95aa2a74d0624bb6c7d53e7a0d35536253
User & Date: dan 2010-11-29 17:55:19
Context
2010-11-29
18:22
On *BSD systems, reduce the number of open connections used by wal3.test to avoid running out of file-descriptors. check-in: 0a3cba95 user: dan tags: trunk
17:55
Fix compiler warnings discovered while building SQLite on http://www.devio.us/. check-in: 5602ec95 user: dan tags: trunk
16:10
Add tests for very small cache-sizes (less than 10 pages). check-in: 46b3fbda user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts3/fts3_expr.c.

   781    781       }
   782    782     }
   783    783   
   784    784     return sqlite3_finalize(pStmt);
   785    785   }
   786    786   
   787    787   /*
   788         -** This function is part of the test interface for the query parser. It
   789         -** writes a text representation of the query expression pExpr into the
   790         -** buffer pointed to by argument zBuf. It is assumed that zBuf is large 
   791         -** enough to store the required text representation.
          788  +** Return a pointer to a buffer containing a text representation of the
          789  +** expression passed as the first argument. The buffer is obtained from
          790  +** sqlite3_malloc(). It is the responsibility of the caller to use 
          791  +** sqlite3_free() to release the memory. If an OOM condition is encountered,
          792  +** NULL is returned.
          793  +**
          794  +** If the second argument is not NULL, then its contents are prepended to 
          795  +** the returned expression text and then freed using sqlite3_free().
   792    796   */
   793         -static void exprToString(Fts3Expr *pExpr, char *zBuf){
          797  +static char *exprToString(Fts3Expr *pExpr, char *zBuf){
   794    798     switch( pExpr->eType ){
   795    799       case FTSQUERY_PHRASE: {
   796    800         Fts3Phrase *pPhrase = pExpr->pPhrase;
   797    801         int i;
   798         -      zBuf += sprintf(zBuf, "PHRASE %d %d", pPhrase->iColumn, pPhrase->isNot);
   799         -      for(i=0; i<pPhrase->nToken; i++){
   800         -        zBuf += sprintf(zBuf," %.*s",pPhrase->aToken[i].n,pPhrase->aToken[i].z);
   801         -        zBuf += sprintf(zBuf,"%s", (pPhrase->aToken[i].isPrefix?"+":""));
          802  +      zBuf = sqlite3_mprintf(
          803  +          "%zPHRASE %d %d", zBuf, pPhrase->iColumn, pPhrase->isNot);
          804  +      for(i=0; zBuf && i<pPhrase->nToken; i++){
          805  +        zBuf = sqlite3_mprintf("%z %.*s%s", zBuf, 
          806  +            pPhrase->aToken[i].n, pPhrase->aToken[i].z,
          807  +            (pPhrase->aToken[i].isPrefix?"+":"")
          808  +        );
   802    809         }
   803         -      return;
          810  +      return zBuf;
   804    811       }
   805    812   
   806    813       case FTSQUERY_NEAR:
   807         -      zBuf += sprintf(zBuf, "NEAR/%d ", pExpr->nNear);
          814  +      zBuf = sqlite3_mprintf("%zNEAR/%d ", zBuf, pExpr->nNear);
   808    815         break;
   809    816       case FTSQUERY_NOT:
   810         -      zBuf += sprintf(zBuf, "NOT ");
          817  +      zBuf = sqlite3_mprintf("%zNOT ", zBuf);
   811    818         break;
   812    819       case FTSQUERY_AND:
   813         -      zBuf += sprintf(zBuf, "AND ");
          820  +      zBuf = sqlite3_mprintf("%zAND ", zBuf);
   814    821         break;
   815    822       case FTSQUERY_OR:
   816         -      zBuf += sprintf(zBuf, "OR ");
          823  +      zBuf = sqlite3_mprintf("%zOR ", zBuf);
   817    824         break;
   818    825     }
   819    826   
   820         -  zBuf += sprintf(zBuf, "{");
   821         -  exprToString(pExpr->pLeft, zBuf);
   822         -  zBuf += strlen(zBuf);
   823         -  zBuf += sprintf(zBuf, "} ");
          827  +  if( zBuf ) zBuf = sqlite3_mprintf("%z{", zBuf);
          828  +  if( zBuf ) zBuf = exprToString(pExpr->pLeft, zBuf);
          829  +  if( zBuf ) zBuf = sqlite3_mprintf("%z} {", zBuf);
          830  +
          831  +  if( zBuf ) zBuf = exprToString(pExpr->pRight, zBuf);
          832  +  if( zBuf ) zBuf = sqlite3_mprintf("%z}", zBuf);
   824    833   
   825         -  zBuf += sprintf(zBuf, "{");
   826         -  exprToString(pExpr->pRight, zBuf);
   827         -  zBuf += strlen(zBuf);
   828         -  zBuf += sprintf(zBuf, "}");
          834  +  return zBuf;
   829    835   }
   830    836   
   831    837   /*
   832    838   ** This is the implementation of a scalar SQL function used to test the 
   833    839   ** expression parser. It should be called as follows:
   834    840   **
   835    841   **   fts3_exprtest(<tokenizer>, <expr>, <column 1>, ...);
................................................................................
   852    858     int rc;
   853    859     char **azCol = 0;
   854    860     const char *zExpr;
   855    861     int nExpr;
   856    862     int nCol;
   857    863     int ii;
   858    864     Fts3Expr *pExpr;
          865  +  char *zBuf = 0;
   859    866     sqlite3 *db = sqlite3_context_db_handle(context);
   860    867   
   861    868     if( argc<3 ){
   862    869       sqlite3_result_error(context, 
   863    870           "Usage: fts3_exprtest(tokenizer, expr, col1, ...", -1
   864    871       );
   865    872       return;
................................................................................
   894    901     for(ii=0; ii<nCol; ii++){
   895    902       azCol[ii] = (char *)sqlite3_value_text(argv[ii+2]);
   896    903     }
   897    904   
   898    905     rc = sqlite3Fts3ExprParse(
   899    906         pTokenizer, azCol, nCol, nCol, zExpr, nExpr, &pExpr
   900    907     );
   901         -  if( rc==SQLITE_NOMEM ){
          908  +  if( rc!=SQLITE_OK && rc!=SQLITE_NOMEM ){
          909  +    sqlite3_result_error(context, "Error parsing expression", -1);
          910  +  }else if( rc==SQLITE_NOMEM || !(zBuf = exprToString(pExpr, 0)) ){
   902    911       sqlite3_result_error_nomem(context);
   903         -    goto exprtest_out;
   904         -  }else if( rc==SQLITE_OK ){
   905         -    char zBuf[4096];
   906         -    exprToString(pExpr, zBuf);
          912  +  }else{
   907    913       sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
   908         -    sqlite3Fts3ExprFree(pExpr);
   909         -  }else{
   910         -    sqlite3_result_error(context, "Error parsing expression", -1);
          914  +    sqlite3_free(zBuf);
   911    915     }
          916  +
          917  +  sqlite3Fts3ExprFree(pExpr);
   912    918   
   913    919   exprtest_out:
   914    920     if( pModule && pTokenizer ){
   915    921       rc = pModule->xDestroy(pTokenizer);
   916    922     }
   917    923     sqlite3_free(azCol);
   918    924   }

Changes to src/os_unix.c.

  5453   5453     int rc = -1;
  5454   5454     UNUSED_PARAMETER(myHostID);
  5455   5455   
  5456   5456     /* create a new path by replace the trailing '-conch' with '-break' */
  5457   5457     pathLen = strlcpy(tPath, cPath, MAXPATHLEN);
  5458   5458     if( pathLen>MAXPATHLEN || pathLen<6 || 
  5459   5459        (strlcpy(&tPath[pathLen-5], "break", 6) != 5) ){
  5460         -    sprintf(errmsg, "path error (len %d)", (int)pathLen);
         5460  +    sqlite3_snprintf(sizeof(errmsg),errmsg,"path error (len %d)",(int)pathLen);
  5461   5461       goto end_breaklock;
  5462   5462     }
  5463   5463     /* read the conch content */
  5464   5464     readLen = pread(conchFile->h, buf, PROXY_MAXCONCHLEN, 0);
  5465   5465     if( readLen<PROXY_PATHINDEX ){
  5466         -    sprintf(errmsg, "read error (len %d)", (int)readLen);
         5466  +    sqlite3_snprintf(sizeof(errmsg),errmsg,"read error (len %d)",(int)readLen);
  5467   5467       goto end_breaklock;
  5468   5468     }
  5469   5469     /* write it out to the temporary break file */
  5470   5470     fd = open(tPath, (O_RDWR|O_CREAT|O_EXCL), SQLITE_DEFAULT_FILE_PERMISSIONS);
  5471   5471     if( fd<0 ){
  5472         -    sprintf(errmsg, "create failed (%d)", errno);
         5472  +    sqlite3_snprintf(sizeof(errmsg), errmsg, "create failed (%d)", errno);
  5473   5473       goto end_breaklock;
  5474   5474     }
  5475   5475     if( pwrite(fd, buf, readLen, 0) != (ssize_t)readLen ){
  5476         -    sprintf(errmsg, "write failed (%d)", errno);
         5476  +    sqlite3_snprintf(sizeof(errmsg), errmsg, "write failed (%d)", errno);
  5477   5477       goto end_breaklock;
  5478   5478     }
  5479   5479     if( rename(tPath, cPath) ){
  5480         -    sprintf(errmsg, "rename failed (%d)", errno);
         5480  +    sqlite3_snprintf(sizeof(errmsg), errmsg, "rename failed (%d)", errno);
  5481   5481       goto end_breaklock;
  5482   5482     }
  5483   5483     rc = 0;
  5484   5484     fprintf(stderr, "broke stale lock on %s\n", cPath);
  5485   5485     close(conchFile->h);
  5486   5486     conchFile->h = fd;
  5487   5487     conchFile->openFlags = O_RDWR | O_CREAT;