fixed various warnings and obvious errors reported by clang compiler and the coverity tool

n/t