Fix warnings with clang

Clang has more powerful static analysis of code (supposedly) and catches some warnings
that were not there in GCC. This fixes the code to prevent those warnings.