nano-node icon indicating copy to clipboard operation
nano-node copied to clipboard

Make silent the overflow report for uint256_t hash calculator (UBSan report)

Open thsfs opened this issue 3 years ago • 0 comments

Got an UBSan error report from Address Sanitizer when running it upon core_test.

/ws/nano-node/nano/lib/numbers.hpp:278:46: runtime error: unsigned integer overflow: 18363490017020192492 + 15047902047331995846 cannot be represented in type 'unsigned long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /ws/nano-node/nano/lib/numbers.hpp:278:46 in 

The overflow is expected as part of the hash calculation, but this should ideally not trigger an error.

Code portion from which the complain comes from:

template <>
struct hash<::nano::uint256_union>
{
	size_t operator() (::nano::uint256_union const & data_a) const
	{
		return data_a.qwords[0] + data_a.qwords[1] + data_a.qwords[2] + data_a.qwords[3];
	}
};

OS: Ubuntu 20.04

thsfs avatar Jan 07 '22 21:01 thsfs