Fixes from SCA

Several fixes for master from SCA (cppcheck), like:
- reduce scope of variables
- pass function parameter by reference
- prefer prefix ++/--operator for non-trivial iterator
- fix inefficient checking for variable emptiness
- remove slow and redundant c_str() calls