Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make silent the overflow report for xorshift1024star calculation #3659

Open
thsfs opened this issue Jan 7, 2022 · 0 comments
Open

Make silent the overflow report for xorshift1024star calculation #3659

thsfs opened this issue Jan 7, 2022 · 0 comments

Comments

@thsfs
Copy link
Contributor

thsfs commented Jan 7, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants