Misc fixes found by clang

Some general purpose fixes which apply to both gcc and clang.