Ensure randomly generated rowids never go negative.

FossilOrigin-Name: 631423677bd7043e99987edc633005443125181c
This commit is contained in:
shaneh 2010-09-01 02:37:56 +00:00
parent c311feec55
commit c4d340a096
3 changed files with 22 additions and 16 deletions

View File

@ -1,5 +1,5 @@
C Do\snot\sclear\sthe\sinternal\s"schema\shas\schanged"\sflag\swhen\sperforming\sa\ssavepoint\srollback.\sThe\sschema\schanges\smay\snot\shave\staken\splace\swithin\sthe\ssavepoint\sbeing\srolled\sback.
D 2010-08-31T16:25:20
C Ensure\srandomly\sgenerated\srowids\snever\sgo\snegative.
D 2010-09-01T02:37:56
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in c599a15d268b1db2aeadea19df2adc3bf2eb6bee
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -222,7 +222,7 @@ F src/update.c 227e6cd512108b84f69421fc6c7aa1b83d60d6e0
F src/utf.c 1baeeac91707a4df97ccc6141ec0f808278af685
F src/util.c 5f5f4db4e799224713582bb49124827b16aa8e54
F src/vacuum.c 241a8386727c1497eba4955933356dfba6ff8c9f
F src/vdbe.c 41a186c0f29ee2e9fcd8754d7e792540f3c0db40
F src/vdbe.c 20ef377f7915a7076af6f4c9ffe2f920e34484fa
F src/vdbe.h 4de0efb4b0fdaaa900cf419b35c458933ef1c6d2
F src/vdbeInt.h a247bd5448039e83394bf4179975b2ae0092874c
F src/vdbeapi.c bec07756e1b3ec5cd054ce8d32a80787763fd07e
@ -851,7 +851,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P 7c4f80ad272138cd4ab30455fae6a36498362933
R 9842f8753de011b5314161323062b619
U dan
Z 858a8b145c877bef8fc144001bc5b64b
P c2a84430d3b6bb53b19af9294973575178290f93
R dfa25dc2885cfefe1659176091b19b37
U shaneh
Z 79cc05c849b02833caa229e781acac58

View File

@ -1 +1 @@
c2a84430d3b6bb53b19af9294973575178290f93
631423677bd7043e99987edc633005443125181c

View File

@ -3719,18 +3719,24 @@ case OP_NewRowid: { /* out2-prerelease */
*/
assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is
** an AUTOINCREMENT table. */
/* on the first attempt, simply do one more than previous */
v = db->lastRowid;
v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
v++; /* ensure non-zero */
cnt = 0;
do{
if( cnt==0 && (v&0xffffff)==v ){
v++;
while( ((rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)v, 0, &res))==SQLITE_OK)
&& (res==0)
&& (++cnt<100)){
/* collision - try another random rowid */
sqlite3_randomness(sizeof(v), &v);
if( cnt<5 ){
/* try "small" random rowids for the initial attempts */
v &= 0xffffff;
}else{
sqlite3_randomness(sizeof(v), &v);
if( cnt<5 ) v &= 0xffffff;
v &= (MAX_ROWID>>1); /* ensure doesn't go negative */
}
rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)v, 0, &res);
cnt++;
}while( cnt<100 && rc==SQLITE_OK && res==0 );
v++; /* ensure non-zero */
}
if( rc==SQLITE_OK && res==0 ){
rc = SQLITE_FULL; /* IMP: R-38219-53002 */
goto abort_due_to_error;