Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752192AbdHLRla (ORCPT ); Sat, 12 Aug 2017 13:41:30 -0400 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:51589 "EHLO out4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752011AbdHLRl1 (ORCPT ); Sat, 12 Aug 2017 13:41:27 -0400 X-ME-Sender: X-Sasl-enc: CEz9Wil1Fn3gIQkeKnPzBhsWeZx9K2+L2z18dQrZCO+F 1502559075 From: Michael Sartain To: Steven Rostedt Cc: Michael Sartain , linux-kernel@vger.kernel.org Subject: [PATCH 4/5] trace-cmd: Use unsigned values in Hsieh's trace_hash fast hash function Date: Sat, 12 Aug 2017 11:30:46 -0600 Message-Id: <20170812173047.840-5-mikesart@fastmail.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170812173047.840-1-mikesart@fastmail.com> References: <20170812173047.840-1-mikesart@fastmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1037 Lines: 39 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 --- 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