3 ms·
There is no easy way out when you're working with C: either you handle all possible UB cases with exhaustive checks, or you move on to another language. (TIP:
by flykespice 1y ago
There is no easy way out when you're working with C: either you handle all possible UB cases with exhaustive checks, or you move on to another language.
(TIP: choose the latter)
- jeroenhd 1y agoVery few programming languages default to checked increments. Most Rust or Java programmers would make the same mistake. Writing a function to do a checked addition like in other languages isn't exactly difficult, either.
- paulddraper 1y agoYes but those languages have defined overflow.
- cozzyd 1y ago-fwrapv
- deleted 1y ago[deleted]
- koito17 1y ago> Most Rust or Java programmers would make the same mistake. Detecting these mistakes in Rust is not too difficult. In debug builds, integer overflow triggers a panic[1]. Additionally, clippy (the official linter of Rust), has a rule[2] to detect this mistake. [1] https://doc.rust-lang.org/book/ch03-02-data-types.html#integer-overflow https://doc.rust-lang.org/book/ch03-02-data-types.html#integ... [2] https://rust-lang.github.io/rust-clippy/master/index.html#arithmetic_side_effects https://rust-lang.github.io/rust-clippy/master/index.html#ar...
- account42 1y agoYou can also just use ubsan if you want the runtime checks for overflows in C/C++, no need to switch languages for this.
- zelphirkalt 1y agoMany other languages automatically switch to a big integer number type, or have arbitrary size integers anyway.
- account42 1y agoWhich is a great way to turn an overflow into a denial of service as suddenly algorithms that were optimized for simple integer arithmetic slow to a crawl.
- uecker 1y agoFor signed overflow you can just turn on the sanitizer in trapping mode. Exhaustive checks is also not that terrible.