Hacker News new | past | comments | ask | show | jobs | submit login

Integer overflow is usually logic error, so a reasonable default behavior would be a trap instead of silent overflow (regardless of how signed integrers are stored in memory). Some architectures support that (e.g. MIPS).



The article mentions cases where integer overflow is expected behavior.


C already offers 'unsigned' type variants that offers defined overflow (together with non-negative range).

It would be useful to have another type variant that offers defined overflow (like in unsigned) together with signed range for such cases. But it still makes sense for basic integers to have overflow as UD, as in most cases it is not expected behavior.

Note that in current C, if one needs defined overflow on signed integers, one can cast them to unsigned, to the operation and cast result back to int. That makes it implementation-defined instead of undefined.


> as in most cases it is not expected behavior

Yeah, but the gotcha happens when it is expected behavior.


-fsanitize-undefined-trap-on-error




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: