Fixes for more cppcheck issues

These commits address issues like:
- use static_cast instead of C-Style cast
- remove unused variables
- perform initialization of variables in initialization list of constructor
- use %u to format unsigned in snprintf()
- remove never executed statements after return
- reduce scope of some variables
- catch exception by reference
- return 'const string' instead of 'const char *' to avoid potentially dangerous usage of std::string::c_str on return from a function
- prefer prefix ++/--operator for non-primitive types