Fix compilation and warnings against master

A few of the warnings were because `int` return codes are being cast to `u64` before being compared against 0, so there are a few bugs fixed in here.