▲ | Sharlin 4 days ago | ||||||||||||||||
Um, there are the cases new == old and new > old. And all the more specific cases new == old + n. I haven’t seen the code so this is just speculation, but there are plenty of ways how an unexpected, "can never happen" comparison result causes immediate UB because there’s no execution path to handle it, causing garbage to be returned from a function (and if that garbage was supposed to be a pointer, well…) or even execution never hitting a `ret` and just proceeding to execute whatever is next in memory. Another super easy way to enter UB land by assuming an integer is nonnegative is array indexing.
Everything is fine as long as i isn’t negative. But if it is… (note that negative % positive == negative in C) | |||||||||||||||||
▲ | account42 4 days ago | parent [-] | ||||||||||||||||
Dividing by a difference that is suddenly zero is another possibility. | |||||||||||||||||
|