A more common type of problem in C++ is a null-pointer dereference, as follows:
int main(void)
{
int *p = 0;
*p = 42;
}
This results in the following:
In the preceding example, we create a pointer to an integer and set it to 0 (that is, a NULL pointer). We then dereference the NULL pointer and set its value, resulting in a segmentation fault, which UBSAN is capable of detecting as the program crashes.