nano-node
nano-node copied to clipboard
Make silent the overflow report for xorshift1024star calculation
Got an UBSan error report from Address Sanitizer when running it upon core_test.
/ws/nano-node/nano/node/xorshift.hpp:18:12: runtime error: left shift of 3860899979500397099 by 31 places cannot be represented in type 'uint64_t' (aka 'unsigned long')
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /ws/nano-node/nano/node/xorshift.hpp:18:12 in
The overflow is expected as part of the calculation, but this should ideally not trigger an error.
Code portion from which the complain comes from:
class xorshift1024star final
{
public:
std::array<uint64_t, 16> s;
unsigned p{ 0 };
uint64_t next ()
{
auto p_l (p);
auto pn ((p_l + 1) & 15);
p = pn;
uint64_t s0 = s[p_l];
uint64_t s1 = s[pn];
s1 ^= s1 << 31; // a
s1 ^= s1 >> 11; // b
s0 ^= s0 >> 30; // c
return (s[pn] = s0 ^ s1) * 1181783497276652981LL;
}
};
OS: Ubuntu 20.04