Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

13
  • 4
    This is so important! If the code that fixes the bug is somewhat counterintuitive, I'll often write a comment like "We need to foo the bar here, see bugtracker #1234". It doesn't make sense to copy all of the bug report into a code comment, but I do want to be able to understand the reason for that extra code in a year or 5. Commented Mar 16, 2023 at 15:41
  • 1
    +1. Another variation is that a compiler will sometimes make an incorrect "optimization", so the transform gets disabled in cases that cannot be proven sound. Someone else notices the compiler isn't performing the optimization in cases where it would be useful and "fixes" it so it will perform the transform in those cases (but also in the erroneous ones). Commented Mar 16, 2023 at 16:03
  • 2
    Hopefully, a test was implemented that ensures this bug is fixed, and after the audacious programmer simplifying the code removed the bugfix this test fails, before the newly faulty code goes into production and annoys the customers enough to file a bug report, or shuts the powerplant down. Commented Mar 17, 2023 at 2:42
  • 2
    @supercat 98% of these cases are caused by buggy code and a programmer who insists they are never wrong and the compiler must be wrong. Commented Mar 17, 2023 at 14:36
  • 1
    @supercat are you talking about this bug? gcc.gnu.org/bugzilla/show_bug.cgi?id=61502 there seems to be consensus that such pointers may compare equal but are not actually the same pointer; the comparison is not undefined behavior, but the outcome is unspecified (uncertain); the pointers are not the same, even if they compare equal, so dereferencing the one-past-the-end pointer is undefined behaviour. In fact two pointers may contain the exact same 1s and 0s and yet dereferencing one is undefined but not the other. If your code even cares about these dark corners of C, it's wrong. Commented Mar 17, 2023 at 14:56