4 ms·
Any C code that performs a calculation which would silently be wrong or crash if the values were not correct (even though they are) is inherently unsafe.
by kazinator 4y ago
Any C code that performs a calculation which would silently be wrong or crash if the values were not correct (even though they are) is inherently unsafe.
- turminal 4y agoThat's a weird way to put it. If your function assumes some constraints on the input it gets and you give it data that violates its constraints, it's going to fail in some way. Sure, C makes it worse by making it harder to verify the assumptions and constraints, but by your definition every function that operates on sorted arrays and doesn't verify the input is sorted is inherently unsafe, regardless of the language.
- jsjohnst 4y ago> but by your definition every function that operates on sorted arrays and doesn't verify the input is sorted is inherently unsafe Are you claiming it’s not? verify all input should be the baseline to call something safe imho.
- turminal 4y agoSure, but that's not a meaningful definition of safety, because according to this definition writing a safe O(log n) binary search is impossible in every single mainstream language in existence.