httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@locus.apache.org
Subject cvs commit: apache-2.0/src/lib/apr/tables apr_hash.c
Date Mon, 30 Oct 2000 19:56:39 GMT
fanf        00/10/30 11:56:39

  Modified:    src/lib/apr/tables apr_hash.c
  Log:
  Fix hash resizing: the hash table size was updated before the array was,
  so when iterating through the old array in order to move the elements to
  the new array we'd go strolling off the end and into outer space.
  
  Submitted by:	Karl Fogel <kfogel@galois.collab.net>
  Message-ID:	<200010272139.e9RLdoi28113@galois.collab.net>
  
  Revision  Changes    Path
  1.8       +10 -8     apache-2.0/src/lib/apr/tables/apr_hash.c
  
  Index: apr_hash.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/tables/apr_hash.c,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -u -r1.7 -r1.8
  --- apr_hash.c	2000/10/16 12:32:42	1.7
  +++ apr_hash.c	2000/10/30 19:56:37	1.8
  @@ -122,9 +122,9 @@
    * Hash creation functions.
    */
   
  -static apr_hash_entry_t **alloc_array(apr_hash_t *ht)
  +static apr_hash_entry_t **alloc_array(apr_hash_t *ht, apr_size_t max)
   {
  -   return apr_pcalloc(ht->pool, sizeof(*ht->array) * (ht->max + 1));
  +   return apr_pcalloc(ht->pool, sizeof(*ht->array) * (max + 1));
   }
   
   APR_DECLARE(apr_hash_t *) apr_make_hash(apr_pool_t *pool)
  @@ -134,7 +134,7 @@
       ht->pool = pool;
       ht->count = 0;
       ht->max = INITIAL_MAX;
  -    ht->array = alloc_array(ht);
  +    ht->array = alloc_array(ht, ht->max);
       return ht;
   }
   
  @@ -178,22 +178,25 @@
   
   
   /*
  - * Resizing a hash table
  + * Expanding a hash table
    */
   
  -static void resize_array(apr_hash_t *ht)
  +static void expand_array(apr_hash_t *ht)
   {
       apr_hash_index_t *hi;
       apr_hash_entry_t **new_array;
  +    apr_size_t new_max;
       int i;
   
  -    new_array = alloc_array(ht);
  +    new_max = ht->max * 2 + 1;
  +    new_array = alloc_array(ht, new_max);
       for (hi = apr_hash_first(ht); hi; hi = apr_hash_next(hi)) {
   	i = hi->this->hash & ht->max;
   	hi->this->next = new_array[i];
   	new_array[i] = hi->this;
       }	       
       ht->array = new_array;
  +    ht->max = new_max;
   }
   
   /*
  @@ -274,8 +277,7 @@
       *hep = he;
       /* check that the collision rate isn't too high */
       if (++ht->count > ht->max) {
  -	ht->max = ht->max * 2 + 1;
  -	resize_array(ht);
  +	expand_array(ht);
       }
       return hep;
   }
  
  
  

Mime
View raw message