3 ms·
They might be referring to eg. the `_Nonnull` annotation being added to memset. The result is that this: if (ptr == null) { set_some_flag = true; }
by kllrnohj 4y ago
They might be referring to eg. the `_Nonnull` annotation being added to memset. The result is that this:
if (ptr == null) {
set_some_flag = true;
} else {
set_some_flag = false;
}
memset(ptr, 0, size);
Will never see `set_some_flag == true`, as the memset call guarantees that ptr is not null, otherwise it's UB, and therefore the earlier `if` statement is always false and the optimizer will remove it.
Now the bug here is changing the definition of memset to match its documentation a solid, what, 20? 30? years after it was first defined, especially when that "null isn't allowed" isn't useful behavior. After all, every memset ever implemented already totally handles null w/ size = 0 without any issue. And it was indeed rather quickly reverted as a change. But that really broke people's minds around UB propagation with modern optimizing passes.