about summary refs log tree commit diff
path: root/nss
diff options
context:
space:
mode:
authorSiddhesh Poyarekar <siddhesh@redhat.com>2012-11-28 06:45:50 +0530
committerSiddhesh Poyarekar <siddhesh@redhat.com>2012-11-28 06:45:50 +0530
commit0817d63dd1f8e165f8ef6590bf4feddf06705381 (patch)
treeaa8f8ee80db1dde9b73eacad849ed04b9393e9bb /nss
parentde2fd463b1c0310d75084b6d774fb974075a4ad9 (diff)
downloadglibc-0817d63dd1f8e165f8ef6590bf4feddf06705381.tar.gz
glibc-0817d63dd1f8e165f8ef6590bf4feddf06705381.tar.xz
glibc-0817d63dd1f8e165f8ef6590bf4feddf06705381.zip
Fix hashtable size calculation when database has exactly one record
The hash function needs a hashtable of at least size 3 or greater.
Diffstat (limited to 'nss')
-rw-r--r--nss/makedb.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/nss/makedb.c b/nss/makedb.c
index 8d7d027b74..e372f5d77e 100644
--- a/nss/makedb.c
+++ b/nss/makedb.c
@@ -591,13 +591,16 @@ copy_valstr (const void *nodep, const VISIT which, const int depth)
 }
 
 
+/* Determine if the candidate is prime by using a modified trial division
+   algorithm. The candidate must be both odd and greater than 4.  */
 static int
 is_prime (size_t candidate)
 {
-  /* No even number and none less than 10 will be passed here.  */
   size_t divn = 3;
   size_t sq = divn * divn;
 
+  assert (candidate > 4 && candidate % 2 != 0);
+
   while (sq < candidate && candidate % divn != 0)
     {
       ++divn;
@@ -612,8 +615,8 @@ is_prime (size_t candidate)
 static size_t
 next_prime (size_t seed)
 {
-  /* Make it definitely odd.  */
-  seed |= 1;
+  /* Make sure that we're always greater than 4.  */
+  seed = (seed + 4) | 1;
 
   while (!is_prime (seed))
     seed += 2;