fix compiler warnings and a crash (try #2)

A few patches that fix compiler warnings. At least the -1 vs. NULL case probably also fixes a crash.