Fix coverity warnings about dereferencing end() iterators.

Refs #9926
Merge branch 'bugfix/9926_coverity_issues_mgigg' into develop