Re:Falsehoods programmers believe about undefined behavior
by caf on Monday November 28, 2022 @09:07AM
(#33773778)
No, that transformation is straight-up buggy unless the compiler can also prove that n > 0 (ie by inlining the bar() function into a context where n is always positive).
If you had *p == 0 before calling bar(p, 0) then *p had better not be 1 after!
If you had *p == 0 before calling bar(p, 0) then *p had better not be 1 after!