Result of overflow on signed integer arithmetic is undefined in C/C++ standard.
So in previous version clang was compiling the statement as (int)a > (int)b (i.e. assuming no overflow), which leads to incorrect result.
Correct deterministic behavior means doing overflow arithmetic as unsigned, i.e.
a != b && a - b <= UINT_MAX / 2
// Compare position even when wrapped around
static inline bool isAfter(unsigned a, unsigned b) {
- return (int)a - (int)b > 0;
+ return a != b && a - b <= UINT_MAX / 2;
}
static LogWriter vlog("Congestion");