Undefined Behavior in C / C++
System programming languages such as c grant compiler writers freedom to generate efficient code for a specific instruction set by defining certain language constructs as undefined behavior. Unfortunately, the rules for what is undefined behavior are subtle and programmers make mistakes that sometimes lead to security vulnerabilities. As an example of undefined behavior in the C programming language, consider integer division with zero as the divisor. Some languages such as C/C++ define many constructs as undefined behavior, while other languages, for example Java, have less undefined behavior. But the existence of undefined behavior in higher-level languages such as Java shows this trade-off is not limited to low-level system languages alone. C compilers trust the programmer not to submit code that has undefined behavior, and they optimize code under that assumption. The C FAQ defines “undefined behavior” like this: Anything at all can happen; the Standard imposes no r...