Miscellaneous cppcheck and other fixes

Like #268 but for master, not stable-0.8. Sorry!

I'm happy to squash things if the commit history gets too detailed ;)
@xhochy Something worth backporting to stable for 0.8?