check ptr before dereference