iter: protect against overflow and infinite loop.