# HG changeset patch # User Richard M. Stallman # Date 888806488 0 # Node ID 22c48e547cb0e4ceb548c380a0b08bb1d0344abf # Parent ceb05db73a63adcbff3de648f3c2868fde3efe4e (update_interval): Properly update `position' field of used intervals. diff -r ceb05db73a63 -r 22c48e547cb0 src/intervals.c --- a/src/intervals.c Mon Mar 02 02:40:53 1998 +0000 +++ b/src/intervals.c Mon Mar 02 02:41:28 1998 +0000 @@ -672,7 +672,8 @@ } /* Find the interval containing POS given some non-NULL INTERVAL - in the same tree. */ + in the same tree. Note that we need to update interval->position + if we go down the tree. */ INTERVAL update_interval (i, pos) register INTERVAL i; @@ -686,22 +687,31 @@ if (pos < i->position) { /* Move left. */ - if (pos >= i->position - TOTAL_LENGTH (i->left)) - i = i->left; /* Move to the left child */ + if (pos >= i->position - TOTAL_LENGTH (i->left)) + { + i->left->position = i->position - TOTAL_LENGTH (i->left) + + LEFT_TOTAL_LENGTH (i->left); + i = i->left; /* Move to the left child */ + } else if (NULL_PARENT (i)) error ("Point before start of properties"); - else i = i->parent; + else + i = i->parent; continue; } else if (pos >= INTERVAL_LAST_POS (i)) { /* Move right. */ - if (pos < INTERVAL_LAST_POS (i) + TOTAL_LENGTH (i->right)) - i = i->right; /* Move to the right child */ + if (pos < INTERVAL_LAST_POS (i) + TOTAL_LENGTH (i->right)) + { + i->right->position = INTERVAL_LAST_POS (i) + + LEFT_TOTAL_LENGTH (i->right); + i = i->right; /* Move to the right child */ + } else if (NULL_PARENT (i)) error ("Point after end of properties"); else - i = i->parent; + i = i->parent; continue; } else