Medium
A null check after the first dereference
deviceId is compiled at -O2 with Clang or GCC, using default flags. What happens to the null check on line (2) in the generated code?
main.cpp
struct Device { int flags; int id; };
void logMissing();
int deviceId(Device* dev) {
int flags = dev->flags; // (1)
if (dev == nullptr) { // (2)
logMissing();
return -1;
}
return (flags & 1) ? dev->id : 0;
}44 of 44 in Compilers