about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2008-11-01 15:39:48 +0000
committerUlrich Drepper <drepper@redhat.com>2008-11-01 15:39:48 +0000
commit64647f9aa8727fdcb4c58c7542beca3732148d0a (patch)
tree620968113f0d265fd042c3a3095ec53ea36e219d
parentacd44dbc7a0e6001406eb9e46eecab3ae34d9966 (diff)
downloadglibc-64647f9aa8727fdcb4c58c7542beca3732148d0a.tar.gz
glibc-64647f9aa8727fdcb4c58c7542beca3732148d0a.tar.xz
glibc-64647f9aa8727fdcb4c58c7542beca3732148d0a.zip
[BZ #6966]
2008-11-01  Ulrich Drepper  <drepper@redhat.com>
	[BZ #6966]
	* misc/hsearch_r.c (hsearch_r): Fix secondary hash function.
-rw-r--r--ChangeLog7
-rw-r--r--misc/hsearch_r.c17
2 files changed, 12 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index bfd6957368..74e1523849 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,14 @@
+2008-11-01  Ulrich Drepper  <drepper@redhat.com>
+
+	[BZ #6966]
+	* misc/hsearch_r.c (hsearch_r): Fix secondary hash function.
+
 2008-10-24  Joseph Myers  <joseph@codesourcery.com>
 	    Ulrich Drepper  <drepper@redhat.com>
 
 	* math/tgmath.h (__floating_type): Use __builtin_classify_type in
 	definition for GCC 3.1 and later.
-		
+
 2008-10-31  Jakub Jelinek  <jakub@redhat.com>
 
 	* elf/dl-tls.c (__tls_get_addr): After calling _dl_update_slotinfo
diff --git a/misc/hsearch_r.c b/misc/hsearch_r.c
index cb4d67466b..c855a41846 100644
--- a/misc/hsearch_r.c
+++ b/misc/hsearch_r.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 1993,1995-1997,2002,2005,2007 Free Software Foundation, Inc.
+/* Copyright (C) 1993,1995-1997,2002,2005,2007,2008
+   Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1993.
 
@@ -154,18 +155,11 @@ hsearch_r (item, action, retval, htab)
     }
 
   /* First hash function: simply take the modul but prevent zero. */
-  hval %= htab->size;
-  if (hval == 0)
-    ++hval;
-
-  /* The first index tried. */
-  idx = hval;
+  idx = hval % htab->size + 1;
 
   if (htab->table[idx].used)
     {
       /* Further action might be required according to the action value. */
-      unsigned hval2;
-
       if (htab->table[idx].used == hval
 	  && strcmp (item.key, htab->table[idx].entry.key) == 0)
 	{
@@ -174,7 +168,8 @@ hsearch_r (item, action, retval, htab)
 	}
 
       /* Second hash function, as suggested in [Knuth] */
-      hval2 = 1 + hval % (htab->size - 2);
+      unsigned int hval2 = 1 + hval % (htab->size - 2);
+      unsigned int first_idx = idx;
 
       do
 	{
@@ -186,7 +181,7 @@ hsearch_r (item, action, retval, htab)
 	    idx -= hval2;
 
 	  /* If we visited all entries leave the loop unsuccessfully.  */
-	  if (idx == hval)
+	  if (idx == first_idx)
 	    break;
 
             /* If entry is found use it. */