Fix problems found by Coverity. See <https://info.ravenbrook.com/mail/2014/04/10/23-23-42/0/> for full analysis.