backport-1.7-3832

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