Return-Path: X-Original-To: apmail-apr-commits-archive@www.apache.org Delivered-To: apmail-apr-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 32F289A2E for ; Sat, 28 Jan 2012 15:54:52 +0000 (UTC) Received: (qmail 78137 invoked by uid 500); 28 Jan 2012 15:54:51 -0000 Delivered-To: apmail-apr-commits-archive@apr.apache.org Received: (qmail 78036 invoked by uid 500); 28 Jan 2012 15:54:50 -0000 Mailing-List: contact commits-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: Reply-To: dev@apr.apache.org List-Id: Delivered-To: mailing list commits@apr.apache.org Received: (qmail 78029 invoked by uid 99); 28 Jan 2012 15:54:50 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 28 Jan 2012 15:54:50 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 28 Jan 2012 15:54:43 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id BCF80238890B for ; Sat, 28 Jan 2012 15:54:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1237078 - /apr/apr/trunk/tables/apr_hash.c Date: Sat, 28 Jan 2012 15:54:22 -0000 To: commits@apr.apache.org From: bojan@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120128155422.BCF80238890B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bojan Date: Sat Jan 28 15:54:22 2012 New Revision: 1237078 URL: http://svn.apache.org/viewvc?rev=1237078&view=rev Log: Further improve hash randomisation: Fix naming of a static function. Randomise final hash produced by any hash function, using default hash function and seed. Modified: apr/apr/trunk/tables/apr_hash.c Modified: apr/apr/trunk/tables/apr_hash.c URL: http://svn.apache.org/viewvc/apr/apr/trunk/tables/apr_hash.c?rev=1237078&r1=1237077&r2=1237078&view=diff ============================================================================== --- apr/apr/trunk/tables/apr_hash.c (original) +++ apr/apr/trunk/tables/apr_hash.c Sat Jan 28 15:54:22 2012 @@ -106,7 +106,7 @@ APR_DECLARE(apr_hash_t *) apr_hash_make( ht->seed = (unsigned int)((now >> 32) ^ now ^ (apr_uintptr_t)pool ^ (apr_uintptr_t)ht ^ (apr_uintptr_t)&now) - 1; ht->array = alloc_array(ht, ht->max); - ht->hash_func = NULL; + ht->hash_func = apr_hashfunc_default; return ht; } @@ -207,9 +207,8 @@ static void expand_array(apr_hash_t *ht) ht->max = new_max; } -static unsigned int apr_hashfunc_default_internal(const char *char_key, - apr_ssize_t *klen, - unsigned int hash) +static unsigned int hashfunc_default(const char *char_key, apr_ssize_t *klen, + unsigned int hash) { const unsigned char *key = (const unsigned char *)char_key; const unsigned char *p; @@ -271,7 +270,7 @@ static unsigned int apr_hashfunc_default APR_DECLARE_NONSTD(unsigned int) apr_hashfunc_default(const char *char_key, apr_ssize_t *klen) { - return apr_hashfunc_default_internal(char_key, klen, 0); + return hashfunc_default(char_key, klen, 0); } /* @@ -290,11 +289,10 @@ static apr_hash_entry_t **find_entry(apr { apr_hash_entry_t **hep, *he; unsigned int hash; + apr_ssize_t hlen = sizeof(hash); - if (ht->hash_func) - hash = ht->hash_func(key, &klen); - else - hash = apr_hashfunc_default_internal(key, &klen, ht->seed); + hash = ht->hash_func(key, &klen); + hash = hashfunc_default((char *)&hash, &hlen, ht->seed); /* scan linked list */ for (hep = &ht->array[hash & ht->max], he = *hep; @@ -435,6 +433,7 @@ APR_DECLARE(apr_hash_t *) apr_hash_merge apr_hash_entry_t *iter; apr_hash_entry_t *ent; unsigned int i, j, k, hash; + apr_ssize_t hlen = sizeof(hash); #if APR_POOL_DEBUG /* we don't copy keys and values, so it's necessary that @@ -484,11 +483,8 @@ APR_DECLARE(apr_hash_t *) apr_hash_merge for (k = 0; k <= overlay->max; k++) { for (iter = overlay->array[k]; iter; iter = iter->next) { - if (res->hash_func) - hash = res->hash_func(iter->key, &iter->klen); - else - hash = apr_hashfunc_default_internal(iter->key, &iter->klen, - res->seed); + hash = res->hash_func(iter->key, &iter->klen); + hash = hashfunc_default((char*)&hash, &hlen, res->seed); i = hash & res->max; for (ent = res->array[i]; ent; ent = ent->next) { if ((ent->klen == iter->klen) &&