1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-22 23:02:54 +03:00

Silence warning in older versions of Valgrind

Due to misunderstanding on my part, commit 235328ee4 did not go far
enough to silence older versions of Valgrind. For those, it was the bit
scan that was problematic, not the subsequent bit-masking operation. To
fix, use the unaligned path for the trailing bytes. Since we don't have
a bit scan here anymore, also remove some comments and endian-specific
coding around that.

Reported-by: Anton A. Melnikov <a.melnikov@postgrespro.ru>
Discussion: https://postgr.es/m/f3aa2d45-3b28-41c5-9499-a1bc30e0f8ec@postgrespro.ru
Backpatch-through: 17
This commit is contained in:
John Naylor 2025-02-24 18:03:29 +07:00
parent 2421e9a51d
commit 0600d276d4

View File

@ -14,8 +14,6 @@
#ifndef HASHFN_UNSTABLE_H
#define HASHFN_UNSTABLE_H
#include "port/pg_bitutils.h"
#include "port/pg_bswap.h"
/*
* fasthash is a modification of code taken from
@ -262,26 +260,13 @@ fasthash_accum_cstring_aligned(fasthash_state *hs, const char *str)
/*
* For every chunk of input, check for zero bytes before mixing into the
* hash. The chunk with zeros must contain the NUL terminator. We arrange
* so that zero_byte_low tells us not only that a zero exists, but also
* where it is, so we can hash the remainder of the string.
*
* The haszero64 calculation will set bits corresponding to the lowest
* byte where a zero exists, so that suffices for little-endian machines.
* For big-endian machines, we would need bits set for the highest zero
* byte in the chunk, since the trailing junk past the terminator could
* contain additional zeros. haszero64 does not give us that, so we
* byteswap the chunk first.
* hash. The chunk with zeros must contain the NUL terminator.
*/
for (;;)
{
uint64 chunk = *(uint64 *) str;
#ifdef WORDS_BIGENDIAN
zero_byte_low = haszero64(pg_bswap64(chunk));
#else
zero_byte_low = haszero64(chunk);
#endif
if (zero_byte_low)
break;
@ -290,13 +275,8 @@ fasthash_accum_cstring_aligned(fasthash_state *hs, const char *str)
str += FH_SIZEOF_ACCUM;
}
/*
* The byte corresponding to the NUL will be 0x80, so the rightmost bit
* position will be in the range 7, 15, ..., 63. Turn this into byte
* position by dividing by 8.
*/
remainder = pg_rightmost_one_pos64(zero_byte_low) / BITS_PER_BYTE;
fasthash_accum(hs, str, remainder);
/* mix in remaining bytes */
remainder = fasthash_accum_cstring_unaligned(hs, str);
str += remainder;
return str - start;