Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
e232038e
Unverified
Commit
e232038e
authored
6 years ago
by
Adam Cozzette
Committed by
GitHub
6 years ago
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4624 from eughermann/hash-ub-fix
Fix undefined behavior in hash function.
parents
6ab3196d
72d18e3f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
7 deletions
+7
-7
descriptor.cc
src/google/protobuf/descriptor.cc
+7
-7
No files found.
src/google/protobuf/descriptor.cc
View file @
e232038e
...
...
@@ -406,9 +406,10 @@ typedef std::pair<const EnumDescriptor*, int> EnumIntPair;
template
<
typename
PairType
>
struct
PointerIntegerPairHash
{
size_t
operator
()(
const
PairType
&
p
)
const
{
// FIXME(kenton): What is the best way to compute this hash? I have
// no idea! This seems a bit better than an XOR.
return
reinterpret_cast
<
intptr_t
>
(
p
.
first
)
*
((
1
<<
16
)
-
1
)
+
p
.
second
;
static
const
size_t
prime1
=
16777499
;
static
const
size_t
prime2
=
16777619
;
return
reinterpret_cast
<
size_t
>
(
p
.
first
)
*
prime1
^
static_cast
<
size_t
>
(
p
.
second
)
*
prime2
;
}
#ifdef _MSC_VER
...
...
@@ -424,11 +425,10 @@ struct PointerIntegerPairHash {
struct
PointerStringPairHash
{
size_t
operator
()(
const
PointerStringPair
&
p
)
const
{
// FIXME(kenton): What is the best way to compute this hash? I have
// no idea! This seems a bit better than an XOR.
static
const
size_t
prime
=
16777619
;
hash
<
const
char
*>
cstring_hash
;
return
reinterpret_cast
<
intptr_t
>
(
p
.
first
)
*
((
1
<<
16
)
-
1
)
+
cstring_hash
(
p
.
second
);
return
reinterpret_cast
<
size_t
>
(
p
.
first
)
*
prime
^
static_cast
<
size_t
>
(
cstring_hash
(
p
.
second
)
);
}
#ifdef _MSC_VER
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment