Fix warnings

A bunch of both msvc and coverity.