During our classification, we find some potential infinite bugs caused by undefined behavior and the termination of these programs may be different in different compilers and platforms. The best-known examples of undefined behaviors in programming languages come from C and C++, which have hundreds of them, including simple local operations (overflowing signed integer arithmetic). Undefined Behavior could make unexpected consequences (eg, Silent Breakage, Time Bombs), which depends on different compilers and platforms.The unexpected consequences can affect the termination of loops. In our study, undefined behavior is a root cause of infinite loop, accounting for 1.9% of all loop bugs and involving 2.92% projects.
We show a potential non-termination loop bug from ``FFmpeg''.
url:https://github.com/FFmpeg/FFmpeg/commit/d597655f771979c70c08f8f8ed84c1319da121e8
commit:d597655f771979c70c08f8f8ed84c1319da121e8
When the value of bytes is 8, uint64_t >> 64 is an undefined operation leading to the undefined behavior. Its value varies in different compilers and platforms, ie, the loop can be infinitely executed if its value is parsed as non-zero. The confirmation of this category of bugs is difficult. We confirmed these bugs from: 1) the commit messages that clearly point out the non-termination and 2) we reproduce them by simplifying the program. For example, we compile the above loop with gcc (version 7.3.0) in Ubuntu SMP Tue. When the value of val was initialized to -1, this loop falls into infinite loop.