Comment by mitxela
2 hours ago
You might ask why it's important that the first loop terminates since in this case the extra side effect would just be a dead store - but if the first loop doesn't terminate then it's possible B is an invalid pointer and then accessing it during the first loop is UB when it shouldn't be. Making a nonterminating loop UB is the patch for this.
The standard example is a linked list instead of an array because the compiler can't prove it never has a cycle.
No comments yet
Contribute on Hacker News ↗