From patchwork Wed Oct 5 14:01:34 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 1288 Return-Path: Received: from contumacia.investici.org (contumacia.investici.org [178.255.144.35]) by open-mesh.org (Postfix) with ESMTPS id 427F5600730 for ; Wed, 5 Oct 2011 16:02:30 +0200 (CEST) Authentication-Results: open-mesh.org; dkim=pass (1024-bit key) header.i=@autistici.org; dkim-adsp=pass Received: from [178.255.144.35] (contumacia [178.255.144.35]) (Authenticated sender: ordex@autistici.org) by localhost (Postfix) with ESMTPSA id 4ABEAE84B6; Wed, 5 Oct 2011 14:02:28 +0000 (UTC) X-DKIM: Sendmail DKIM Filter v2.8.2 contumacia.investici.org 4ABEAE84B6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1317823349; bh=EAhYn+lkaYRysyw139+addyw8NIhhOdvlLDTad4mvQM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=BkOJaKDuoXAL22sOA9Ss0qajMDcA38nOAGkRwtzXVO5mtzqqUfOZgz6sTD7Buh4WD dkzJRcqV3wQ72N0BAiSzd6X4TbzxZizBsI2R8Kqvm5+HTWM/+U0DimIqoGfWwDI0vq MXH7R8EhAp2DOyYGktHZx27AYYZG4yvAIqFnBVSk= From: Antonio Quartulli To: b.a.t.m.a.n@lists.open-mesh.org Date: Wed, 5 Oct 2011 16:01:34 +0200 Message-Id: <1317823294-16922-1-git-send-email-ordex@autistici.org> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1317766324-28264-1-git-send-email-ordex@autistici.org> References: <1317766324-28264-1-git-send-email-ordex@autistici.org> Subject: [B.A.T.M.A.N.] [PATCHv2] batman-adv: fixed hash functions type to uint32_t instead of int X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.13 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Oct 2011 14:02:30 -0000 There are two reasons for this fix: - the result of choose_orig() and vis_choose() is an index and therefore it can't be negative. Hence it is correct to make the return type unsigned too. - sizeof(int) is not the same on ALL the architectures. Since we plan to use choose_orig() as DHT hash function, we need to guarantee that, given the same argument, the result is the same. Then it is correct to explicitly express the size of the return type (and the second argument). Since the expected length is currently 4, uint32_t is the most convenient choice. Signed-off-by: Antonio Quartulli --- Changed commit messages in order to explicitly hash.h | 2 +- originator.h | 2 +- vis.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hash.h b/hash.h index d20aa71..588ef79 100644 --- a/hash.h +++ b/hash.h @@ -33,7 +33,7 @@ typedef int (*hashdata_compare_cb)(const struct hlist_node *, const void *); /* the hashfunction, should return an index * based on the key in the data of the first * argument and the size the second */ -typedef int (*hashdata_choose_cb)(const void *, int); +typedef uint32_t (*hashdata_choose_cb)(const void *, uint32_t); typedef void (*hashdata_free_cb)(struct hlist_node *, void *); struct hashtable_t { diff --git a/originator.h b/originator.h index cfc1f60..67765ff 100644 --- a/originator.h +++ b/originator.h @@ -42,7 +42,7 @@ int orig_hash_del_if(struct hard_iface *hard_iface, int max_if_num); /* hashfunction to choose an entry in a hash table of given size */ /* hash algorithm from http://en.wikipedia.org/wiki/Hash_table */ -static inline int choose_orig(const void *data, int32_t size) +static inline uint32_t choose_orig(const void *data, uint32_t size) { const unsigned char *key = data; uint32_t hash = 0; diff --git a/vis.c b/vis.c index f81a6b6..a9cd152 100644 --- a/vis.c +++ b/vis.c @@ -66,7 +66,7 @@ static int vis_info_cmp(const struct hlist_node *node, const void *data2) /* hash function to choose an entry in a hash table of given size */ /* hash algorithm from http://en.wikipedia.org/wiki/Hash_table */ -static int vis_info_choose(const void *data, int size) +static uint32_t vis_info_choose(const void *data, uint32_t size) { const struct vis_info *vis_info = data; const struct vis_packet *packet;