Coverity fix and better consistency checks

Same thing as v5-34-00.

(There are more items here because your master is a bit outdated.)