Static analysis fixes part 1

I have used static code analysis tool [PVS-Studio](http://www.viva64.com/en/pvs-studio/) and fixed a few issues. Beside a53914b and 3384ec9 there were only small issues. I also added a link in all commit messages to the corresponding description of the issue. There are some more issues reported which I will fix later on.