I did for a while check file==NULL (earlier than c++11), and also file->IsZombie() seperately, if file is a null pointer, or points at null, calling IsZombie() actually causes segment and crashes.
I did have a combination of nullptr/Null or IsZombie(), and if by any reason IsZombie() is called, segment fault.
Well … the behavior of calling a function on a nullptr is “unspecified” behavior and might indeed sometime not crash. What do you expect the behavior to be?
if file is a null pointer, or points at null, calling IsZombie() actually causes segment and crashes.
Yes, that’s why you need to have the 2 test inside the same if statement to benefit from the ‘boolean’ optimized that says that the 2nd part of a OR (||) is not evaluated if the 1st is true. Or you can write it as:
if (file == nullptr) {
return;
} else if (file->IsZombie()) {
delete file;
return;
}