Coverity patches

Copy of #396 with the brace formatting fixed.