4 ms·
From the project home page: "prevents almost all crashes (in theory)" How does it prevent index out of bounds errors and division by zero? No, not even in theo
by sisalcat 12y ago
From the project home page: "prevents almost all crashes (in theory)"
How does it prevent index out of bounds errors and division by zero? No, not even in theory. What a ridiculous claim.
- adamnemecek 12y agoI mean you get an error but not a segfault. Rust crashes on division by zero but honestly, how many crashes have you encountered in the real world due to division by zero?
- pbsd 12y agoProbably quite a few. There's also more than just division by 0 to be wary of: http://blog.cmpxchg8b.com/2013/02/the-other-integer-overflow.html http://blog.cmpxchg8b.com/2013/02/the-other-integer-overflow...
- dbaupp 12y agoYou get a task failure (similar to an exception) on division by 0 too.
- berkut 12y agoQuite a few if you include what happens after a division by zero without proper checking / clamping. Had one the other day when renormalising a Cumulative distribution function wasn't taking into account a possible empty set, and the lookup of the index was invalid due to the division by zero.
- nrc 12y agoAll array indexing is bounds checked, so those kind of errors are prevented. We're still working on the story around overflow checking
- sisalcat 12y agoThis prevents buffer overflow errors, but not crashes.
- dbaupp 12y agoIt prevents the OS killing a misbehaving application (which is what is meant by "crash" in that context). This allows, for example, a multithreaded server application to continue even if one worker task indexes an array incorrectly.
- kzrdude 12y agoIt also prevents an equally important problem: silent passing of errors. It's common for out of bounds accesses or stores in C or C++ to just pass silently, potentially corrupting data.
- b0b_d0e 12y agoindex out of bounds errors are handled in separate ways depending on the kind of array you are using. If I understand how it works correctly, you can be working with one of three main kinds of arrays: slices with a known length, slices with an unknown length, or a growable vector. In the case of slices with a known length, ie: let a = [0]; then trying to say a[1] is a compile error since the compiler knows the length of the array at compile time, it will not let this code compile. In the case of an unknown length at compile time, the compiler cannot really help you here, but it will cause a task failure when you try to access out of bounds (since it does know the length at runtime, it checks to make sure that it is in bounds). This is similar to what happens when you are trying to access an element that doesn't exist on growable vector as well. I hope this information clears up somethings for you and even more so I hope my information is correct! I'm still learning rust, so I still have misunderstandings quite often.
- sisalcat 12y ago> it will cause a task failure i.e. a crash.
- dbaupp 12y agoIt doesn't necessarily take down the whole program, ice. it's recoverable, unlike memory corruption or a segfault. (Yes I know you can install signal handlers for segv, but that is not isolated at a language level like a task failure is with Rust.)