Undefined Behavior in C and C++: An Experiment With Desktop Use Cases
For C and C++ developers and compiler designers, this work provides empirical evidence of the frequency and nature of undefined behavior in real-world desktop usage, though the findings are incremental.
The paper empirically measures the prevalence of undefined behavior in C and C++ programs during typical desktop use of a Linux distribution, finding that undefined behavior is common: 59 tasks generated nearly 11,000 unique warnings from 32 programs, with most related to virtual table pointers.
Undefined behavior is idiomatic to C and C++ programming; such behavior is a use of an erroneous program construct for which the languages impose no requirements, such as integer overflows. The paper presents an empirical experiment seeking to probe the extent of undefined behavior executing underneath typical desktop use of a Linux distribution. The analysis is based on an undefined behavior sanitizer implemented in a compiler. According to the results, undefined behavior is common. By completing 59 simple experimental tasks, nearly 11 thousand unique undefined behavior warnings were generated by 32 unique programs and libraries written in C or C++. Of these warnings, most were associated with the Mesa graphics library and generated by interacting with graphical user interfaces. Merely logging into the GNOME desktop environment generated over 500 unique warnings. Of all warnings, the clear majority was about virtual table pointers. The associated stack traces were also lengthy in general. With these and other results, the paper contributes to the empirical literature on C and C++.