Fix some code bugs identified by scrutinizer-ci.