// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin developers
// Distributed under the MIT software license, see the accompanying
-// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+// file COPYING or https://www.opensource.org/licenses/mit-license.php .
#include "arith_uint256.h"
template <unsigned int BITS>
int base_uint<BITS>::CompareTo(const base_uint<BITS>& b) const
{
+ if ( (uint64_t)pn < 0x1000 || (uint64_t)b.pn <= 0x1000 )
+ {
+ //fprintf(stderr,"CompareTo null %p or %p\n",pn,b.pn);
+ return(0);
+ }
for (int i = WIDTH - 1; i >= 0; i--) {
if (pn[i] < b.pn[i])
return -1;
{
for (int pos = WIDTH - 1; pos >= 0; pos--) {
if (pn[pos]) {
- for (int bits = 31; bits > 0; bits--) {
- if (pn[pos] & 1 << bits)
+ for (size_t bits = 31; bits > 0; bits--) {
+ if (pn[pos] & (1U << bits)) {
return 32 * pos + bits + 1;
+ }
}
return 32 * pos + 1;
}