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