Skip to content

Commit 8ef81fb

Browse files
acozzettecopybara-github
authored andcommitted
Automated rollback of commit 6bde8c4.
PiperOrigin-RevId: 723555860
1 parent 46f9e29 commit 8ef81fb

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

upb/hash/common.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,14 @@ uint32_t _upb_Hash(const void* p, size_t n, uint64_t seed) {
402402
return Wyhash(p, n, seed, kWyhashSalt);
403403
}
404404

405-
// Returns a seed for upb's hash function. For now this is just a hard-coded
406-
// constant, but we are going to randomize it soon.
407-
static uint64_t _upb_Seed(void) { return 0x69835f69597ec1cc; }
405+
static const void* const _upb_seed;
406+
407+
// Returns a random seed for upb's hash function. This does not provide
408+
// high-quality randomness, but it should be enough to prevent unit tests from
409+
// relying on a deterministic map ordering. By returning the address of a
410+
// variable, we are able to get some randomness for free provided that ASLR is
411+
// enabled.
412+
static uint64_t _upb_Seed(void) { return (uint64_t)&_upb_seed; }
408413

409414
static uint32_t _upb_Hash_NoSeed(const char* p, size_t n) {
410415
return _upb_Hash(p, n, _upb_Seed());

0 commit comments

Comments
 (0)