OK… having a hard time following the scenarios you specify. Since it is not apparent from looking at the code that the above loop is safe, it would be worth describing your reasoning in a comment.