4 ms·
The issue there is that you pretty much have to use undefined behaviour in C and certain low-level applications of C++. C is therefore a broken language IMHO, b
by vertex-four 10y ago
The issue there is that you pretty much have to use undefined behaviour in C and certain low-level applications of C++. C is therefore a broken language IMHO, but... there we have it.
- jjnoakes 10y agoI don't think one ever has to rely on undefined behavior. If you think you do, you can usually rewrite your code to avoid it, or rely on implementation defined behavior for specific compilers. And if that is not low level enough, you should be using assembly.
- _pmf_ 10y agoThat's wrong. All firmware I worked with used assembly for early initialization (startup.s) in those cases where the only alternative would be to rely on UB. I've worked with firmware that only worked with -O0 and failed with -O2, but these were always bad implementations, not due to some inherent requirement to rely on UB (most common example: failing to recognize that using volatile does not guarantee a memory barrier).
- vertex-four 10y ago> I've worked with firmware that only worked with -O0 and failed with -O2 But as we can see in this vuln, there's functionality that works in the normal case but where important checks are elided, and compilers might decide not to do anything with a piece of undefined behaviour in one version but not in the next. Whether a piece of code works in -O2 doesn't prove it doesn't contain undefined behaviour.