Fix clang and coverity warnings