mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8203223: Signed integer overflow in ImageStrings::hash_code (libjimage.so)
Perform hash operation on local unsigned type. Reviewed-by: shade, dholmes, alanb
This commit is contained in:
parent
5ee4a26ecb
commit
2bd15814dc
1 changed files with 4 additions and 2 deletions
|
@ -57,14 +57,16 @@ const char FileSeparator = '/';
|
|||
|
||||
// Compute the Perfect Hashing hash code for the supplied UTF-8 string.
|
||||
s4 ImageStrings::hash_code(const char* string, s4 seed) {
|
||||
assert(seed > 0 && "invariant");
|
||||
// Access bytes as unsigned.
|
||||
u1* bytes = (u1*)string;
|
||||
u4 useed = (u4)seed;
|
||||
// Compute hash code.
|
||||
for (u1 byte = *bytes++; byte; byte = *bytes++) {
|
||||
seed = (seed * HASH_MULTIPLIER) ^ byte;
|
||||
useed = (useed * HASH_MULTIPLIER) ^ byte;
|
||||
}
|
||||
// Ensure the result is not signed.
|
||||
return seed & 0x7FFFFFFF;
|
||||
return (s4)(useed & 0x7FFFFFFF);
|
||||
}
|
||||
|
||||
// Match up a string in a perfect hash table.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue