Backport 1.8 3832

Backport #3832: `BUG: fix small issues found with cppcheck`