Fix more cppcheck findings

Mainly reduction of variable scopes and shadowing of variables.

Merge request reports

Loading