- The ReadLE32 etc functions in crypto/common.h where dereferencing type-punned pointers, which is undefined behaviour (and can cause consistent failure on some platforms due to misaligned reads). Fix this by
memcpy()
ing into a local variable first (as accessing a type’s representation through a char* is always allowed). - The scriptnum tests were testing running several arithmetic operations on large integers, triggering signed integer overflow, which is undefined. Fix the tests by using integers limited to +/- 2^40 (larger than anything actually supported in script).
- Fix a memory leak in the wallet tests: CWalletTx objects that weren’t freed - wrap them in a unique_ptr.
- Fix a memory leak in the net tests: a CNode object wasn’t being freed - wrap them in a unique_ptr.
- Fix a memory leak in the rpc auth: a buffer that wasn’t being freed - switch it to a stack-allocated array.
- The REST code for getutxos was using boost::dynamic_bitset, which apparently issues a rightshift by a negative amount. Fix this by replacing it with normal bit/byte vectors.
Now all unit tests and rpc tests run succesfully with -fsanitize=address -fsanitize=undefined -fsanitize=leak in GCC 6.2.0.
Thanks to @kcc for pointing me to these tools.