aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/btree.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/btree.c b/src/btree.c
index f21fce2a5..4176d2c8b 100644
--- a/src/btree.c
+++ b/src/btree.c
@@ -7036,8 +7036,10 @@ static int balance_nonroot(
**
** If neither of the above apply, the page is safe to update.
*/
- for(i=0; i<nNew*2; i++){
- int iPg = (i>=nNew ? i-nNew : nNew-1-i);
+ for(i=1-nNew; i<nNew; i++){
+ int iPg = i<0 ? -i : i;
+ /* iPg takes values from nNew-1 down to 0 then back up to nNew-1 again */
+ assert( iPg>=0 && iPg<nNew );
if( abDone[iPg]==0
&& (iPg==0 || cntOld[iPg-1]>=cntNew[iPg-1] || abDone[iPg-1])
&& (cntNew[iPg]>=cntOld[iPg] || abDone[iPg+1])