Check whether the iterator p == the end iterator before trying to dereference it...