solve cppcheck defects: use of nullptr after check, prefer preincrement to postincrement for iterators