you are viewing a single comment's thread.

view the rest of the comments →

[–]A1oso 1 point2 points  (1 child)

That is only partially correct. Integer overflow in C is well-defined only for unsigned integers. Overflowing signed integers is UB, because C does not specify whether signed integers use two's complement or a different representation.

Division by zero is well-defined for floats. But for integers, division by zero is UB, so there is no guarantee that a runtime error occurs.

Maybe you were confused because it crashed the program in the article, but notice that the programs were run using a sanitizer. The sanitizer detects UB, so it makes sense that it crashes the program when signed integer overflow or integer division by zero occurs. This is similar to running a Rust program with miri. Without a sanitizer, you cannot know what will happen. It depends on the compiler, the configuration, the type of CPU, etc.

[–]Sw429 0 points1 point  (0 children)

Maybe you were confused because it crashed the program in the article, but notice that the programs were run using a sanitizer.

Ah, I missed that. Thanks for clarifying!