Overflow errors

Finally, we can also detect signed integer overflow errors, which are undefined in C++, but highly unlikely to generate a crash, and instead will cause the program to enter a corrupt state (often producing endless loops, out-of-bounds errors, and so on). Consider the following code:

#include <climits>

int main(void)
{
int i = INT_MAX;
i++;
}

This results in the following:

As shown in the preceding example, we create an integer and set it to its maximum value. We then attempt to increase this integer, which would normally flip the integer's sign, an error that UBSAN is capable of detecting.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset