fix compiler warnings and a crash

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