Divide-by-zero errors

One of the easiest examples to demonstrate with UBSAN is the divide-by-zero error, as follows:

int main(void)
{
int n = 42;
int d = 0;

auto f = n/d;
}

When this is run, we see the following:

In the preceding example, we create two integers (a numerator and a denominator) with the denominator set to 0. We then divide the numerator and the denominator resulting in a divide-by-zero error, which UBSAN detects and outputs as the program crashes. 

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

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