Fossil SCM
Align the delta_parse() debug function with the SQLite sources.
Commit
a8dbbac969e19bd87455080c3b83921979af3579beec06cda18d0ba0b2725b55
Parent
3ca3a6a667cf237…
1 file changed
+18
-3
+18
-3
| --- src/deltafunc.c | ||
| +++ src/deltafunc.c | ||
| @@ -251,10 +251,11 @@ | ||
| 251 | 251 | if( rc==SQLITE_OK ){ |
| 252 | 252 | pNew = sqlite3_malloc64( sizeof(*pNew) ); |
| 253 | 253 | *ppVtab = (sqlite3_vtab*)pNew; |
| 254 | 254 | if( pNew==0 ) return SQLITE_NOMEM; |
| 255 | 255 | memset(pNew, 0, sizeof(*pNew)); |
| 256 | + sqlite3_vtab_config(db, SQLITE_VTAB_INNOCUOUS); | |
| 256 | 257 | } |
| 257 | 258 | return rc; |
| 258 | 259 | } |
| 259 | 260 | |
| 260 | 261 | /* |
| @@ -296,15 +297,25 @@ | ||
| 296 | 297 | deltaparsevtab_cursor *pCur = (deltaparsevtab_cursor*)cur; |
| 297 | 298 | const char *z; |
| 298 | 299 | int i = 0; |
| 299 | 300 | |
| 300 | 301 | pCur->iCursor = pCur->iNext; |
| 302 | + if( pCur->iCursor >= pCur->nDelta ){ | |
| 303 | + pCur->eOp = DELTAPARSE_OP_ERROR; | |
| 304 | + pCur->iNext = pCur->nDelta; | |
| 305 | + return SQLITE_OK; | |
| 306 | + } | |
| 301 | 307 | z = pCur->aDelta + pCur->iCursor; |
| 302 | 308 | pCur->a1 = deltaGetInt(&z, &i); |
| 303 | 309 | switch( z[0] ){ |
| 304 | 310 | case '@': { |
| 305 | 311 | z++; |
| 312 | + if( pCur->iNext>=pCur->nDelta ){ | |
| 313 | + pCur->eOp = DELTAPARSE_OP_ERROR; | |
| 314 | + pCur->iNext = pCur->nDelta; | |
| 315 | + break; | |
| 316 | + } | |
| 306 | 317 | pCur->a2 = deltaGetInt(&z, &i); |
| 307 | 318 | pCur->eOp = DELTAPARSE_OP_COPY; |
| 308 | 319 | pCur->iNext = (int)(&z[1] - pCur->aDelta); |
| 309 | 320 | break; |
| 310 | 321 | } |
| @@ -354,12 +365,16 @@ | ||
| 354 | 365 | } |
| 355 | 366 | case DELTAPARSEVTAB_A2: { |
| 356 | 367 | if( pCur->eOp==DELTAPARSE_OP_COPY ){ |
| 357 | 368 | sqlite3_result_int(ctx, pCur->a2); |
| 358 | 369 | }else if( pCur->eOp==DELTAPARSE_OP_INSERT ){ |
| 359 | - sqlite3_result_blob(ctx, pCur->aDelta+pCur->a2, pCur->a1, | |
| 360 | - SQLITE_TRANSIENT); | |
| 370 | + if( pCur->a2 + pCur->a1 > pCur->nDelta ){ | |
| 371 | + sqlite3_result_zeroblob(ctx, pCur->a1); | |
| 372 | + }else{ | |
| 373 | + sqlite3_result_blob(ctx, pCur->aDelta+pCur->a2, pCur->a1, | |
| 374 | + SQLITE_TRANSIENT); | |
| 375 | + } | |
| 361 | 376 | } |
| 362 | 377 | break; |
| 363 | 378 | } |
| 364 | 379 | case DELTAPARSEVTAB_DELTA: { |
| 365 | 380 | sqlite3_result_blob(ctx, pCur->aDelta, pCur->nDelta, SQLITE_TRANSIENT); |
| @@ -383,11 +398,11 @@ | ||
| 383 | 398 | ** Return TRUE if the cursor has been moved off of the last |
| 384 | 399 | ** row of output. |
| 385 | 400 | */ |
| 386 | 401 | static int deltaparsevtabEof(sqlite3_vtab_cursor *cur){ |
| 387 | 402 | deltaparsevtab_cursor *pCur = (deltaparsevtab_cursor*)cur; |
| 388 | - return pCur->eOp==DELTAPARSE_OP_EOF; | |
| 403 | + return pCur->eOp==DELTAPARSE_OP_EOF || pCur->iCursor>=pCur->nDelta; | |
| 389 | 404 | } |
| 390 | 405 | |
| 391 | 406 | /* |
| 392 | 407 | ** This method is called to "rewind" the deltaparsevtab_cursor object back |
| 393 | 408 | ** to the first row of output. This method is always called at least |
| 394 | 409 |
| --- src/deltafunc.c | |
| +++ src/deltafunc.c | |
| @@ -251,10 +251,11 @@ | |
| 251 | if( rc==SQLITE_OK ){ |
| 252 | pNew = sqlite3_malloc64( sizeof(*pNew) ); |
| 253 | *ppVtab = (sqlite3_vtab*)pNew; |
| 254 | if( pNew==0 ) return SQLITE_NOMEM; |
| 255 | memset(pNew, 0, sizeof(*pNew)); |
| 256 | } |
| 257 | return rc; |
| 258 | } |
| 259 | |
| 260 | /* |
| @@ -296,15 +297,25 @@ | |
| 296 | deltaparsevtab_cursor *pCur = (deltaparsevtab_cursor*)cur; |
| 297 | const char *z; |
| 298 | int i = 0; |
| 299 | |
| 300 | pCur->iCursor = pCur->iNext; |
| 301 | z = pCur->aDelta + pCur->iCursor; |
| 302 | pCur->a1 = deltaGetInt(&z, &i); |
| 303 | switch( z[0] ){ |
| 304 | case '@': { |
| 305 | z++; |
| 306 | pCur->a2 = deltaGetInt(&z, &i); |
| 307 | pCur->eOp = DELTAPARSE_OP_COPY; |
| 308 | pCur->iNext = (int)(&z[1] - pCur->aDelta); |
| 309 | break; |
| 310 | } |
| @@ -354,12 +365,16 @@ | |
| 354 | } |
| 355 | case DELTAPARSEVTAB_A2: { |
| 356 | if( pCur->eOp==DELTAPARSE_OP_COPY ){ |
| 357 | sqlite3_result_int(ctx, pCur->a2); |
| 358 | }else if( pCur->eOp==DELTAPARSE_OP_INSERT ){ |
| 359 | sqlite3_result_blob(ctx, pCur->aDelta+pCur->a2, pCur->a1, |
| 360 | SQLITE_TRANSIENT); |
| 361 | } |
| 362 | break; |
| 363 | } |
| 364 | case DELTAPARSEVTAB_DELTA: { |
| 365 | sqlite3_result_blob(ctx, pCur->aDelta, pCur->nDelta, SQLITE_TRANSIENT); |
| @@ -383,11 +398,11 @@ | |
| 383 | ** Return TRUE if the cursor has been moved off of the last |
| 384 | ** row of output. |
| 385 | */ |
| 386 | static int deltaparsevtabEof(sqlite3_vtab_cursor *cur){ |
| 387 | deltaparsevtab_cursor *pCur = (deltaparsevtab_cursor*)cur; |
| 388 | return pCur->eOp==DELTAPARSE_OP_EOF; |
| 389 | } |
| 390 | |
| 391 | /* |
| 392 | ** This method is called to "rewind" the deltaparsevtab_cursor object back |
| 393 | ** to the first row of output. This method is always called at least |
| 394 |
| --- src/deltafunc.c | |
| +++ src/deltafunc.c | |
| @@ -251,10 +251,11 @@ | |
| 251 | if( rc==SQLITE_OK ){ |
| 252 | pNew = sqlite3_malloc64( sizeof(*pNew) ); |
| 253 | *ppVtab = (sqlite3_vtab*)pNew; |
| 254 | if( pNew==0 ) return SQLITE_NOMEM; |
| 255 | memset(pNew, 0, sizeof(*pNew)); |
| 256 | sqlite3_vtab_config(db, SQLITE_VTAB_INNOCUOUS); |
| 257 | } |
| 258 | return rc; |
| 259 | } |
| 260 | |
| 261 | /* |
| @@ -296,15 +297,25 @@ | |
| 297 | deltaparsevtab_cursor *pCur = (deltaparsevtab_cursor*)cur; |
| 298 | const char *z; |
| 299 | int i = 0; |
| 300 | |
| 301 | pCur->iCursor = pCur->iNext; |
| 302 | if( pCur->iCursor >= pCur->nDelta ){ |
| 303 | pCur->eOp = DELTAPARSE_OP_ERROR; |
| 304 | pCur->iNext = pCur->nDelta; |
| 305 | return SQLITE_OK; |
| 306 | } |
| 307 | z = pCur->aDelta + pCur->iCursor; |
| 308 | pCur->a1 = deltaGetInt(&z, &i); |
| 309 | switch( z[0] ){ |
| 310 | case '@': { |
| 311 | z++; |
| 312 | if( pCur->iNext>=pCur->nDelta ){ |
| 313 | pCur->eOp = DELTAPARSE_OP_ERROR; |
| 314 | pCur->iNext = pCur->nDelta; |
| 315 | break; |
| 316 | } |
| 317 | pCur->a2 = deltaGetInt(&z, &i); |
| 318 | pCur->eOp = DELTAPARSE_OP_COPY; |
| 319 | pCur->iNext = (int)(&z[1] - pCur->aDelta); |
| 320 | break; |
| 321 | } |
| @@ -354,12 +365,16 @@ | |
| 365 | } |
| 366 | case DELTAPARSEVTAB_A2: { |
| 367 | if( pCur->eOp==DELTAPARSE_OP_COPY ){ |
| 368 | sqlite3_result_int(ctx, pCur->a2); |
| 369 | }else if( pCur->eOp==DELTAPARSE_OP_INSERT ){ |
| 370 | if( pCur->a2 + pCur->a1 > pCur->nDelta ){ |
| 371 | sqlite3_result_zeroblob(ctx, pCur->a1); |
| 372 | }else{ |
| 373 | sqlite3_result_blob(ctx, pCur->aDelta+pCur->a2, pCur->a1, |
| 374 | SQLITE_TRANSIENT); |
| 375 | } |
| 376 | } |
| 377 | break; |
| 378 | } |
| 379 | case DELTAPARSEVTAB_DELTA: { |
| 380 | sqlite3_result_blob(ctx, pCur->aDelta, pCur->nDelta, SQLITE_TRANSIENT); |
| @@ -383,11 +398,11 @@ | |
| 398 | ** Return TRUE if the cursor has been moved off of the last |
| 399 | ** row of output. |
| 400 | */ |
| 401 | static int deltaparsevtabEof(sqlite3_vtab_cursor *cur){ |
| 402 | deltaparsevtab_cursor *pCur = (deltaparsevtab_cursor*)cur; |
| 403 | return pCur->eOp==DELTAPARSE_OP_EOF || pCur->iCursor>=pCur->nDelta; |
| 404 | } |
| 405 | |
| 406 | /* |
| 407 | ** This method is called to "rewind" the deltaparsevtab_cursor object back |
| 408 | ** to the first row of output. This method is always called at least |
| 409 |