turn on -Werror and fix resulting errors

With length == -1 it will just truncate the file to zero length which seems fine.