Address some minor issues reported by cppcheck

These were related to a) scope of some variable declarations, and b) use
of pre-increment vs. post-increment of non-primitive types (this has a
slight performance hit due to the way that pre- vs. post-increment
operators are overloaded in C++.

Also cleaned up a few places where initialized variables were not being
used.