fix some errors/warnings found by static code analyzer

found by http://www.viva64.com/en/b/0293/