How to stop the clang-instrumented program when the clang-sanitizer finds an error?

Let's say I have the following program:

#include <iostream>

float foo(float f)
    { return (f / 0); }

int main(void) {
    foo(1.0f);
    std::cout << "hello" << std::endl;
}

If I call clang++ -fsanitize=undefined main.cpp && ./a.out, then it will output:

main.cpp:4:32: runtime error: division by zero
hello

Is there a way to abort a.outas soon as an error is detected? That is, in such a way that it displays:

main.cpp:4:32: runtime error: division by zero

without displaying helloon the next line? (because it will be interrupted earlier)

+4
source share
1 answer

You need to use the command line argument -fno-sanitize-recover:

clang++ -fsanitize=undefined -fno-sanitize-recover=undefined main.cpp
+4
source

Source: https://habr.com/ru/post/1666725/


All Articles