fix cppcheck warnings:
- Variable '<varname>' is reassigned a value before the old one has been used.
- Possible inefficient checking for '<varname>' emptiness.