Fix Clang static analysis errors on null pointers. (#460)
Also fix a wrong parameter checking.