Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1710341
| From | Michael Sartain <mikesart@fastmail.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 4/5] trace-cmd: Use unsigned values in Hsieh's trace_hash fast hash function |
| Date | 2017-08-12 19:50 +0200 |
| Message-ID | <udIHU-3VV-5@gated-at.bofh.it> (permalink) |
| References | <udIye-3S9-23@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Signed int values were being used where the original code used uint32_t types:
http://www.azillionmonkeys.com/qed/hash.html
Right shifting negative int values has implementation-defined and left shifting
has undefined behavior.
On my platform (x86_64) right shifting was doing sign extension and filling
high bits with 1s, which is different than the original algorithm.
Signed-off-by: Michael Sartain <mikesart@fastmail.com>
---
trace-hash-local.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/trace-hash-local.h b/trace-hash-local.h
index b2a1002..b3f9b06 100644
--- a/trace-hash-local.h
+++ b/trace-hash-local.h
@@ -22,7 +22,7 @@
static inline unsigned int trace_hash(int val)
{
- int hash, tmp;
+ unsigned int hash, tmp;
hash = 12546869; /* random prime */
@@ -34,7 +34,7 @@ static inline unsigned int trace_hash(int val)
*/
hash += (val & 0xffff);
- tmp = (val >> 16) ^ hash;
+ tmp = ((unsigned int)val >> 16) ^ hash;
hash = (hash << 16) ^ tmp;
hash += hash >> 11;
--
2.13.2
Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread
[PATCH 0/5] trace-cmd: Fixes for four small bugs plus minor cleanup Michael Sartain <mikesart@fastmail.com> - 2017-08-12 19:40 +0200 [PATCH 1/5] trace-cmd: Fix incorrect malloc size arg: *item instead of item Michael Sartain <mikesart@fastmail.com> - 2017-08-12 19:50 +0200 [PATCH 3/5] trace-cmd: Add ULL suffix to MISSING_EVENTS since ints shouldn't be left shifted by 31 Michael Sartain <mikesart@fastmail.com> - 2017-08-12 19:50 +0200 [PATCH 4/5] trace-cmd: Use unsigned values in Hsieh's trace_hash fast hash function Michael Sartain <mikesart@fastmail.com> - 2017-08-12 19:50 +0200
csiph-web