protecting dereferencing of void pointer by if statement