Skip to Content
Advanced C++ Programming Cookbook
book

Advanced C++ Programming Cookbook

by Dr. Rian Quinn
January 2020
Intermediate to advanced
454 pages
11h 25m
English
Packt Publishing
Content preview from Advanced C++ Programming Cookbook

Out-of-bounds errors

Both of the preceding examples could have been detected using a Unix signal handler. In the next example, we will access an array out of bounds, which is undefined in the C++ specification and is a lot more difficult to detect:

int main(void){    int numbers[] = {4, 8, 15, 16, 23, 42};    numbers[10] = 0;}

When executed, we get the following:

As shown in the preceding example, we create an array with 6 elements and then attempt to access the 10th element in the array, which doesn't exist. Attempting to access this element in the array is not guaranteed to generate a segmentation fault. Regardless, UBSAN is capable of detecting ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Modern C++ Programming Cookbook

Modern C++ Programming Cookbook

Marius Bancila

Publisher Resources

ISBN: 9781838559915Supplemental Content