Fix "argument cannot be negative" errors reported by Coverity