SafeArray: add a null pointer check

Thanks @ghost for the report.

Close issue #327