Fix up some things code analysis pointed out.

And added a more general-purpose error displaying method.