Skip to content
Prev 9021 / 12125 Next

[R-pkg-devel] How to identify what flags "Additional Issues" for UBSAN

? Wed, 22 Mar 2023 15:51:54 +0000
"Kenny, Christopher" <christopherkenny at fas.harvard.edu> ?????:
Unfortunately, it's _all_ the sanitizer errors.
You'd be right to think that signed integer overflow just wraps around
on modern CPUs with no adverse effects on the rest of the execution.
Unfortunately, you'd also need to convince the C++ optimiser, and it's
currently allowed to think otherwise.

In C++, signed integer overflow (and other similar errors, such as
casing NaN to an integer) is undefined behaviour, which, according to
the standard, means that anything can happen after that, ranging from
nothing out of order to a crash and also to silent corruption of
important research results. Other languages define integer overflow to
have a more limited impact (wrap the value around or at least guarantee
a crash), but not C and C++. [*]

Thankfully, I only see one spot where you encounter UB, in
src/wilson.cpp line 165, which should be relatively easy to fix by
adjusting your strategy for calculating the maximum number of tries.
(Do you get a NaN when `remaining` is -1? Why is it -1? Or is it 0?)