aboutsummaryrefslogtreecommitdiff
path: root/src/hash.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2017-07-12 16:23:59 -0700
committerPieter Wuille <pieter.wuille@gmail.com>2017-07-12 16:29:48 -0700
commit479afa0f8486146a35f1fb96be1826061ecbcf23 (patch)
treeec44d307a80093d6efb13a71439f17f90781080f /src/hash.cpp
parent2a09a3891fde052a585dc019eea9fba26d42445d (diff)
parent30ac7688e398bbe5400a48ecf0726b679ffb845d (diff)
downloadbitcoin-479afa0f8486146a35f1fb96be1826061ecbcf23.tar.xz
Merge #9804: Fixes subscript 0 (&var[0]) where should use (var.data()) instead.
30ac7688e Fix subscript[0] potential bugs in key.cpp (Jeremy Rubin) 4b1c0f2e2 Remove unnecessary branches in utilstrencodings string constructors. (Jeremy Rubin) e19db7b5a Fix subscript[0] in utilstrencodings.cpp (Jeremy Rubin) bc2e7fd98 Fix subscript[0] in streams.h (Jeremy Rubin) 4cac0d1e0 Fix subscript[0] in validation.cpp (Jeremy Rubin) ac658e55f Fix subscript[0] in torcontrol (Jeremy Rubin) b6856ebed Fix subscript[0] in netaddress.cpp (Jeremy Rubin) 361d95265 Fix subscript[0] in base58.cpp (Jeremy Rubin) 6896dbf16 Cleanup (safe, it was checked) subscript[0] in MurmurHash3 (and cleanup MurmurHash3 to be more clear). (Jeremy Rubin) 96f2119e6 Fix subscript[0] in compressor.cpp (Jeremy Rubin) 500710bd2 Fix 2 subscript[0] bugs in pubkey.cpp, and eliminate one extra size check (Jeremy Rubin) e0451e3e2 Fix subscript[0] bug in net.cpp if GetGroup returns a 0-sized vector (Jeremy Rubin) Tree-SHA512: 5b9103652cf8c615bd8f4f32b3573d291d6b67c39e0308ce00100bc6625f346e8e016b4c999f4f34f5c37ae059490a83c3b513deb21f838af785227d06e02362
Diffstat (limited to 'src/hash.cpp')
-rw-r--r--src/hash.cpp43
1 files changed, 20 insertions, 23 deletions
diff --git a/src/hash.cpp b/src/hash.cpp
index b361c90d16..5a15600be5 100644
--- a/src/hash.cpp
+++ b/src/hash.cpp
@@ -17,36 +17,34 @@ unsigned int MurmurHash3(unsigned int nHashSeed, const std::vector<unsigned char
{
// The following is MurmurHash3 (x86_32), see http://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.cpp
uint32_t h1 = nHashSeed;
- if (vDataToHash.size() > 0)
- {
- const uint32_t c1 = 0xcc9e2d51;
- const uint32_t c2 = 0x1b873593;
+ const uint32_t c1 = 0xcc9e2d51;
+ const uint32_t c2 = 0x1b873593;
- const int nblocks = vDataToHash.size() / 4;
+ const int nblocks = vDataToHash.size() / 4;
- //----------
- // body
- const uint8_t* blocks = &vDataToHash[0] + nblocks * 4;
+ //----------
+ // body
+ const uint8_t* blocks = vDataToHash.data();
- for (int i = -nblocks; i; i++) {
- uint32_t k1 = ReadLE32(blocks + i*4);
+ for (int i = 0; i < nblocks; ++i) {
+ uint32_t k1 = ReadLE32(blocks + i*4);
- k1 *= c1;
- k1 = ROTL32(k1, 15);
- k1 *= c2;
+ k1 *= c1;
+ k1 = ROTL32(k1, 15);
+ k1 *= c2;
- h1 ^= k1;
- h1 = ROTL32(h1, 13);
- h1 = h1 * 5 + 0xe6546b64;
- }
+ h1 ^= k1;
+ h1 = ROTL32(h1, 13);
+ h1 = h1 * 5 + 0xe6546b64;
+ }
- //----------
- // tail
- const uint8_t* tail = (const uint8_t*)(&vDataToHash[0] + nblocks * 4);
+ //----------
+ // tail
+ const uint8_t* tail = vDataToHash.data() + nblocks * 4;
- uint32_t k1 = 0;
+ uint32_t k1 = 0;
- switch (vDataToHash.size() & 3) {
+ switch (vDataToHash.size() & 3) {
case 3:
k1 ^= tail[2] << 16;
case 2:
@@ -57,7 +55,6 @@ unsigned int MurmurHash3(unsigned int nHashSeed, const std::vector<unsigned char
k1 = ROTL32(k1, 15);
k1 *= c2;
h1 ^= k1;
- }
}
//----------