/ Check-in [20a4ca5d]
Login

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

Overview
Comment:Fix some strict-aliasing problems in fts3_expr.c. (CVS 6035)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:20a4ca5d361ecbb982129171f10cccac4f5ad093
User & Date: danielk1977 2008-12-17 15:49:52
Context
2008-12-17
17:30
Add the savepoint feature. This feature is largely untested at this point. (CVS 6036) check-in: 34b56600 user: danielk1977 tags: trunk
15:49
Fix some strict-aliasing problems in fts3_expr.c. (CVS 6035) check-in: 20a4ca5d user: danielk1977 tags: trunk
15:18
Modify fts3 to support a more complex expression syntax that allows parenthesis. The new syntax is not entirely backwards compatible, so is disabled by default. Use -DSQLITE_ENABLE_FTS3_PARENTHESIS to enable it. (CVS 6034) check-in: 7389b9ec user: danielk1977 tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ext/fts3/fts3_expr.c.

151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
...
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
...
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
...
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
  }
  
  *pnConsumed = nConsumed;
  *ppExpr = pRet;
  return rc;
}

void realloc_or_free(void **ppOrig, int nNew){
  void *pRet = sqlite3_realloc(*ppOrig, nNew);
  if( !pRet ){
    sqlite3_free(*ppOrig);
  }
  *ppOrig = pRet;
}

/*
** Buffer zInput, length nInput, contains the contents of a quoted string
** that appeared as part of an fts3 query expression. Neither quote character
** is included in the buffer. This function attempts to tokenize the entire
** input buffer and create an Fts3Expr structure of type FTSQUERY_PHRASE 
................................................................................
    pCursor->pTokenizer = pTokenizer;
    for(ii=0; rc==SQLITE_OK; ii++){
      const char *zToken;
      int nToken, iBegin, iEnd, iPos;
      rc = pModule->xNext(pCursor, &zToken, &nToken, &iBegin, &iEnd, &iPos);
      if( rc==SQLITE_OK ){
        int nByte = sizeof(Fts3Expr) + sizeof(Fts3Phrase);
        realloc_or_free((void **)&p, nByte+ii*sizeof(struct PhraseToken));
        realloc_or_free((void **)&zTemp, nTemp + nToken);
        if( !p || !zTemp ){
          goto no_mem;
        }
        if( ii==0 ){
          memset(p, 0, nByte);
          p->pPhrase = (Fts3Phrase *)&p[1];
          p->eType = FTSQUERY_PHRASE;
................................................................................

  if( rc==SQLITE_DONE ){
    int jj;
    char *zNew;
    int nNew = 0;
    int nByte = sizeof(Fts3Expr) + sizeof(Fts3Phrase);
    nByte += (p->pPhrase->nToken-1) * sizeof(struct PhraseToken);
    realloc_or_free((void **)&p, nByte + nTemp);
    if( !p ){
      goto no_mem;
    }
    p->pPhrase = (Fts3Phrase *)&p[1];
    zNew = &(((char *)p)[nByte]);
    memcpy(zNew, zTemp, nTemp);
    for(jj=0; jj<p->pPhrase->nToken; jj++){
................................................................................
  */
  while( nInput>0 && safe_isspace(*zInput) ){
    nInput--;
    zInput++;
  }

  /* See if we are dealing with a keyword. */
  for(ii=0; ii<sizeof(aKeyword)/sizeof(struct Fts3Keyword); ii++){
    struct Fts3Keyword *pKey = &aKeyword[ii];

    if( (0==sqlite3_fts3_enable_parentheses)
     && (pKey->eType==FTSQUERY_AND || pKey->eType==FTSQUERY_NOT) 
    ){
      continue;
    }







|
|

|

|







 







|
|







 







|







 







|







151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
...
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
...
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
...
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
  }
  
  *pnConsumed = nConsumed;
  *ppExpr = pRet;
  return rc;
}

void *realloc_or_free(void *pOrig, int nNew){
  void *pRet = sqlite3_realloc(pOrig, nNew);
  if( !pRet ){
    sqlite3_free(pOrig);
  }
  return pRet;
}

/*
** Buffer zInput, length nInput, contains the contents of a quoted string
** that appeared as part of an fts3 query expression. Neither quote character
** is included in the buffer. This function attempts to tokenize the entire
** input buffer and create an Fts3Expr structure of type FTSQUERY_PHRASE 
................................................................................
    pCursor->pTokenizer = pTokenizer;
    for(ii=0; rc==SQLITE_OK; ii++){
      const char *zToken;
      int nToken, iBegin, iEnd, iPos;
      rc = pModule->xNext(pCursor, &zToken, &nToken, &iBegin, &iEnd, &iPos);
      if( rc==SQLITE_OK ){
        int nByte = sizeof(Fts3Expr) + sizeof(Fts3Phrase);
        p = realloc_or_free(p, nByte+ii*sizeof(struct PhraseToken));
        zTemp = realloc_or_free(zTemp, nTemp + nToken);
        if( !p || !zTemp ){
          goto no_mem;
        }
        if( ii==0 ){
          memset(p, 0, nByte);
          p->pPhrase = (Fts3Phrase *)&p[1];
          p->eType = FTSQUERY_PHRASE;
................................................................................

  if( rc==SQLITE_DONE ){
    int jj;
    char *zNew;
    int nNew = 0;
    int nByte = sizeof(Fts3Expr) + sizeof(Fts3Phrase);
    nByte += (p->pPhrase->nToken-1) * sizeof(struct PhraseToken);
    p = realloc_or_free(p, nByte + nTemp);
    if( !p ){
      goto no_mem;
    }
    p->pPhrase = (Fts3Phrase *)&p[1];
    zNew = &(((char *)p)[nByte]);
    memcpy(zNew, zTemp, nTemp);
    for(jj=0; jj<p->pPhrase->nToken; jj++){
................................................................................
  */
  while( nInput>0 && safe_isspace(*zInput) ){
    nInput--;
    zInput++;
  }

  /* See if we are dealing with a keyword. */
  for(ii=0; ii<(int)(sizeof(aKeyword)/sizeof(struct Fts3Keyword)); ii++){
    struct Fts3Keyword *pKey = &aKeyword[ii];

    if( (0==sqlite3_fts3_enable_parentheses)
     && (pKey->eType==FTSQUERY_AND || pKey->eType==FTSQUERY_NOT) 
    ){
      continue;
    }