Fix crash due to missing pointer validation