ISD-Sound-and-Lights / eyepatch

Fixtures in. Standard out. -- A CLI utility to create a patch standard from a list of lighting fixtures.
0 stars 0 forks source link

Easy to cause segmentation fault #7

Open il8677 opened 6 years ago

il8677 commented 6 years ago

Fix all the segmantation faults, caused by editing blocks/devices when none exist.

ghost commented 6 years ago

Rather than checking that they exist, why not catch the error caused when they don't exist? That way, you prevent segfault when the block is deleted after checking for it but before editing it.

This is the Python mentality: better to beg forgiveness than ask permission.

il8677 commented 6 years ago

Unlike python, there is no IndexError. Segmentation faults take place as a termination signal (SIGSEV), not as an exception. SIGSEV is much like SIGINT (ctrl+c in your terminal emulator). It is technically possible to catch kill signals, but it's a lot less clean than catching exceptions, if a SIGSEV already happened, it's hard to clean up all the potential problems (like buffer overflows). It's like vaccines vs dealing with diseases, vaccines are generally easier.

In c++, no forgiveness is given. You better make damn sure that your program has no errors, otherwise your integers will suddenly get assigned random values and your strings will commit suicide.

il8677 commented 6 years ago

As a result, we need to check if there are actually blocks or devices to edit, before trying to access arrays with no elements

ghost commented 6 years ago

Oo-er. Makes sense.