10 ms·
This is exactly what assert() does, so literally any C library that contains an assert() can produce a nonrecoverable error. GP's point is that most libraries
by int_19h 2y ago
This is exactly what assert() does, so literally any C library that contains an assert() can produce a nonrecoverable error.
GP's point is that most libraries will not even assert(), but instead just assume the invariant holds and proceed accordingly, resulting in UB. And it is, of course, infeasible for a library to constantly test for invariants holding at every single point in the program. So in practice you have to assume that a library breaking its internal invariants is going to UB. If library dev added some asserts to this, they are doing you a favor by making sure that, at least for some particular subset of broken invariants, that UB is guaranteed to be a clean abort rather than running some code doing god knows what.