bstr: check pointers before memcmp/strncasecmp

This fixes #1155 for me. I think it's the cause of all the invalid parameter errors.