Bugfix/cleanup lib: fix compiler warnings and a crash (try #3)

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