Hacker News new | ask | show | jobs
by c4mpute 1171 days ago
> all you have to do to avoid UB on signed integer overflow is check for overflow before doing the operation

All you have to do is add a check for overflow _that the compiler will not throw away because "UB won't happen"_. The very thing you want to avoid makes avoiding it very hard, and lots of bugs have resulted from compilers "optimizing" away such overflow checks.

1 comments

This is covered in the article and numerous replies in this thread. Use <stdckdint.h>.
stdckdint.h is only available in C23. The problem has existed before that and lead to tons of exploits and bugs.