Core/Misc: Refactor scripts to fix static analysis warnings

Sixth batch of fixes targeting 100 issues reported by Coverity