Do not dereference an iterator when it point to the end. Thanks to Markus Moll for catching my broken fix from a previous change. Change-Id: I37d0185cfc6f86d0c31f580ca988577abc168ab5