Catching -fsanitize=integer generate error ?


We are trying to use -fsanitize=integer to detect integer overflow errors. The message "runtime error: signed integer overflow" is generated, but is seems not as a catchable C++ exception. We would like to use try {…code that possibly overflow…. } catch (std::runtime_error& e) { } kind of code to handle the exception.

It that possible? If not is there any alternative to detect integer overflow errors ?


Stéphane Letz

You can use “UBSAN_OPTIONS=halt_on_error=1” in the environment to detect the problem without letting execution continue.

Maybe you could use -fsanitize-trap=undefined and -ftrap=function?