▲ | phkahler 4 days ago | |||||||||||||||||||||||||
That doesn't make sense. If new < old cant happen there is no need to make a comparison. Stack corruption? Nah, its a counter not an index or pointer or it would fail sooner. But then what is the failure? IDK | ||||||||||||||||||||||||||
▲ | jraph 4 days ago | parent | next [-] | |||||||||||||||||||||||||
Assuming new > old doesn't mean you actually make the comparison, but rather that the code is written with the belief that new > old. This code behaves correctly under this assumption, but might be doing something very bad that leads to a crash if the new < old. An actual analysis would be needed to understand the actual cause of the crash. | ||||||||||||||||||||||||||
▲ | Sharlin 4 days ago | parent | prev [-] | |||||||||||||||||||||||||
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) | ||||||||||||||||||||||||||
|