Improve dynamic cast null-check

Found by coverity