Page MenuHomePhabricator

Fix undefined behavior in avalanche.cpp
ClosedPublic

Authored by Fabien on May 20 2019, 11:39.

Details

Summary

In the MMIX LCG calculation, the right side calculation underlying type
is signed. This causes the undefined behavior sanitizer to detect a
signed integer overflow.
This diff sets the constants to unsigned long long to enforce the
underlying type to be unsigned and get rid of this error.

Test Plan

With the UBSAN activated, run

test_bitcoin -t avalanche_tests

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

In src/tests/lcg.h it should pick up the same problem, does it?

This revision is now accepted and ready to land.May 20 2019, 15:10
deadalnix requested changes to this revision.May 20 2019, 16:37

If the problem is that nodeid is signed, then this is what needs fixing, not all the constants.

This revision now requires changes to proceed.May 20 2019, 16:37

Cast nodeid instead of the constants.

This revision is now accepted and ready to land.May 20 2019, 20:29
This revision was automatically updated to reflect the committed changes.