diff --git a/src/core/ddsi/src/ddsi_sertopic_default.c b/src/core/ddsi/src/ddsi_sertopic_default.c index d8a05fc..ece3872 100644 --- a/src/core/ddsi/src/ddsi_sertopic_default.c +++ b/src/core/ddsi/src/ddsi_sertopic_default.c @@ -56,7 +56,7 @@ static uint32_t sertopic_default_hash (const struct ddsi_sertopic *tpcmn) { const struct ddsi_sertopic_default *tp = (struct ddsi_sertopic_default *) tpcmn; uint32_t h = 0; - h = ddsrt_mh3 (&tp->native_encoding_identifier, sizeof (tp->native_encoding_identifier), 0); + h = ddsrt_mh3 (&tp->native_encoding_identifier, sizeof (tp->native_encoding_identifier), h); h = ddsrt_mh3 (&tp->type.m_size, sizeof (tp->type.m_size), h); h = ddsrt_mh3 (&tp->type.m_align, sizeof (tp->type.m_align), h); h = ddsrt_mh3 (&tp->type.m_flagset, sizeof (tp->type.m_flagset), h); diff --git a/src/ddsrt/src/mh3.c b/src/ddsrt/src/mh3.c index f186e95..1b57de7 100644 --- a/src/ddsrt/src/mh3.c +++ b/src/ddsrt/src/mh3.c @@ -25,38 +25,41 @@ uint32_t ddsrt_mh3 (const void *key, size_t len, uint32_t seed) const uint32_t c2 = 0x1b873593; uint32_t h1 = seed; - const uint32_t *blocks = (const uint32_t *) (data + nblocks * 4); - for (intptr_t i = -nblocks; i; i++) - { - uint32_t k1 = blocks[i]; - k1 *= c1; - k1 = DDSRT_MH3_ROTL32 (k1, 15); - k1 *= c2; + if(len){ + const uint32_t *blocks = (const uint32_t *) (data + nblocks * 4); + for (intptr_t i = -nblocks; i; i++) + { + uint32_t k1 = blocks[i]; - h1 ^= k1; - h1 = DDSRT_MH3_ROTL32 (h1, 13); - h1 = h1 * 5 + 0xe6546b64; - } - - const uint8_t *tail = data + nblocks * 4; - uint32_t k1 = 0; - switch (len & 3) - { - case 3: - k1 ^= (uint32_t) tail[2] << 16; - /* FALLS THROUGH */ - case 2: - k1 ^= (uint32_t) tail[1] << 8; - /* FALLS THROUGH */ - case 1: - k1 ^= (uint32_t) tail[0]; k1 *= c1; k1 = DDSRT_MH3_ROTL32 (k1, 15); k1 *= c2; + h1 ^= k1; - /* FALLS THROUGH */ - }; + h1 = DDSRT_MH3_ROTL32 (h1, 13); + h1 = h1 * 5 + 0xe6546b64; + } + + const uint8_t *tail = data + nblocks * 4; + uint32_t k1 = 0; + switch (len & 3) + { + case 3: + k1 ^= (uint32_t) tail[2] << 16; + /* FALLS THROUGH */ + case 2: + k1 ^= (uint32_t) tail[1] << 8; + /* FALLS THROUGH */ + case 1: + k1 ^= (uint32_t) tail[0]; + k1 *= c1; + k1 = DDSRT_MH3_ROTL32 (k1, 15); + k1 *= c2; + h1 ^= k1; + /* FALLS THROUGH */ + } + } /* finalization */ h1 ^= (uint32_t) len;