News for hackers. Stuff that matters.
Re:Falsehoods programmers believe about undefined behavior by olliej on Monday November 28, 2022 @11:38AM (#33775780)
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.

There are no comments on this comment yet.