69 ms·
memset, memcpy, and memmove, etc all depend on UB. memset and memcpy read and write padding bytes, which is UB. If you try to say memset/cpy is a "primitive op
by olliej 4y ago
memset, memcpy, and memmove, etc all depend on UB.
memset and memcpy read and write padding bytes, which is UB. If you try to say memset/cpy is a "primitive operation", then you're still stuck with the "correct" struct initialization (memset, bzero) being UB if you did something like:
void f(bool condition) {
if (condition) {
struct structwithpadding thing;
bzero(&thing, sizeof(thing));
} else {
printf("wat\n");
}
}
The ludicrously broad definition of what UB apparent allows, this can be "optimized" to
void f(bool condition) {
printf("wat\n");
}
Because bzero() writes to padding, and that is UB, which means the condition==true branch "can't happen" \o/
memmove falls to UB much requires pointer comparisons between pointers to different objects, which is UB.