Fix infinite loop in BitSet

This is a failing unit test (infinite loop) plus a one-line fix. They are in separate commits, but you may want to squash them into a single commit for the sake of bisectability.