Skip to content

Commit e85e19b

Browse files
committed
Changed Get64(.) to GetLow64()
The function Get64(.) has a bug in case the width is not divisible by 64. Since it is only ever used as Get64(0) this simply changes it to this special case. Additionally, an assert is added, and a cast to prevent a compiler error.
1 parent 6e77920 commit e85e19b

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/addrman.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ int CAddrInfo::GetTriedBucket(const std::vector<unsigned char> &nKey) const
1414
CDataStream ss1(SER_GETHASH, 0);
1515
std::vector<unsigned char> vchKey = GetKey();
1616
ss1 << nKey << vchKey;
17-
uint64_t hash1 = Hash(ss1.begin(), ss1.end()).Get64();
17+
uint64_t hash1 = Hash(ss1.begin(), ss1.end()).GetLow64();
1818

1919
CDataStream ss2(SER_GETHASH, 0);
2020
std::vector<unsigned char> vchGroupKey = GetGroup();
2121
ss2 << nKey << vchGroupKey << (hash1 % ADDRMAN_TRIED_BUCKETS_PER_GROUP);
22-
uint64_t hash2 = Hash(ss2.begin(), ss2.end()).Get64();
22+
uint64_t hash2 = Hash(ss2.begin(), ss2.end()).GetLow64();
2323
return hash2 % ADDRMAN_TRIED_BUCKET_COUNT;
2424
}
2525

@@ -29,11 +29,11 @@ int CAddrInfo::GetNewBucket(const std::vector<unsigned char> &nKey, const CNetAd
2929
std::vector<unsigned char> vchGroupKey = GetGroup();
3030
std::vector<unsigned char> vchSourceGroupKey = src.GetGroup();
3131
ss1 << nKey << vchGroupKey << vchSourceGroupKey;
32-
uint64_t hash1 = Hash(ss1.begin(), ss1.end()).Get64();
32+
uint64_t hash1 = Hash(ss1.begin(), ss1.end()).GetLow64();
3333

3434
CDataStream ss2(SER_GETHASH, 0);
3535
ss2 << nKey << vchSourceGroupKey << (hash1 % ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP);
36-
uint64_t hash2 = Hash(ss2.begin(), ss2.end()).Get64();
36+
uint64_t hash2 = Hash(ss2.begin(), ss2.end()).GetLow64();
3737
return hash2 % ADDRMAN_NEW_BUCKET_COUNT;
3838
}
3939

src/uint256.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class base_uint
203203
{
204204
// prefix operator
205205
int i = 0;
206-
while (--pn[i] == -1 && i < WIDTH-1)
206+
while (--pn[i] == (uint32_t)-1 && i < WIDTH-1)
207207
i++;
208208
return *this;
209209
}
@@ -370,9 +370,10 @@ class base_uint
370370
return sizeof(pn);
371371
}
372372

373-
uint64_t Get64(int n=0) const
373+
uint64_t GetLow64() const
374374
{
375-
return pn[2*n] | (uint64_t)pn[2*n+1] << 32;
375+
assert(WIDTH >= 2);
376+
return pn[0] | (uint64_t)pn[1] << 32;
376377
}
377378

378379
// unsigned int GetSerializeSize(int nType=0, int nVersion=PROTOCOL_VERSION) const

0 commit comments

Comments
 (0)