A wonderful example of this was some Linux kernel code that ended up causing a security vulnerability. It was something approximating:
int foo(struct data *data) {
struct member *member = &data->member;
if (data == NULL) {
return -EINVAL;
}
// Do stuff
}
Assigning a value to member is just a matter of taking data and adding the value of member, so won't explode if data is NULL since it's not actually dereferencing that address. But this is still in undefined behaviour territory, so gcc assumed that we must know that data could never be NULL and optimised out the check.
This sort of thing is why I have definite feelings about the use of C in security sensitive contexts.
This sort of thing is why I have definite feelings about the use of C in security sensitive contexts.