If there's a bug that triggers undefined behavior in a piece of code, is the undefined behavior consistent each time running it? and changes each time compiling it?For example if you had some C code that does some string manipulation. You compile it, run it 3 times and the output is consistent of weird characters like ABCE*D-*+. You compile it again and the next time it run it 3 times it just crashes.I'm sorry if the description is a little ambiguous, as I'm trying to figure this out myself.
Consistency of Undefined behavior
c;bug;undefined behavior
No. The consistency of undefined behaviour is undefined.Speaking practically, when you've caused undefined behaviour by dereferencing a null pointer, you can probably expect fairly deterministic results (segmentation fault) at least on the same computer, because that computer has been constructed to behave that way for null pointer dereferences.But when you've caused it by dereferencing uninitialised pointers, whether the ensuing dereference is even physically possible will depend on what that unspecified, uninitialised value is, which may depend on what code has run before, and with what user inputs, and in what order. Like a dice roll, it's not actually random, but it's also neither fully deterministic nor usefully predictable. Add optimisations into the mix and it's no longer practical to attempt rationalising about any of it.That's why we tend not to go into any further detail about the causes of specific symptoms of undefined behaviour; there's rarely any point.