Building with optimization in debug mode revealed code that could in theory result in undefined behavior.