Open il8677 opened 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.
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.
As a result, we need to check if there are actually blocks or devices to edit, before trying to access arrays with no elements
Oo-er. Makes sense.
Fix all the segmantation faults, caused by editing blocks/devices when none exist.