mirror of
https://sourceware.org/git/glibc.git
synced 2024-12-22 19:00:07 +00:00
Fix hashtable size calculation when database has exactly one record
The hash function needs a hashtable of at least size 3 or greater.
This commit is contained in:
parent
de2fd463b1
commit
0817d63dd1
@ -1,3 +1,10 @@
|
|||||||
|
2012-11-28 Siddhesh Poyarekar <siddhesh@redhat.com>
|
||||||
|
Carlos O'Donell <carlos_odonell@mentor.com>
|
||||||
|
|
||||||
|
* nss/makedb.c (is_prime): Assert that input is odd and greater
|
||||||
|
than 4. Note that fact in a comment too.
|
||||||
|
(next_prime): Add 4 to input.
|
||||||
|
|
||||||
2012-11-27 Siddhesh Poyarekar <siddhesh@redhat.com>
|
2012-11-27 Siddhesh Poyarekar <siddhesh@redhat.com>
|
||||||
|
|
||||||
[BZ #11741]
|
[BZ #11741]
|
||||||
|
@ -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
|
static int
|
||||||
is_prime (size_t candidate)
|
is_prime (size_t candidate)
|
||||||
{
|
{
|
||||||
/* No even number and none less than 10 will be passed here. */
|
|
||||||
size_t divn = 3;
|
size_t divn = 3;
|
||||||
size_t sq = divn * divn;
|
size_t sq = divn * divn;
|
||||||
|
|
||||||
|
assert (candidate > 4 && candidate % 2 != 0);
|
||||||
|
|
||||||
while (sq < candidate && candidate % divn != 0)
|
while (sq < candidate && candidate % divn != 0)
|
||||||
{
|
{
|
||||||
++divn;
|
++divn;
|
||||||
@ -612,8 +615,8 @@ is_prime (size_t candidate)
|
|||||||
static size_t
|
static size_t
|
||||||
next_prime (size_t seed)
|
next_prime (size_t seed)
|
||||||
{
|
{
|
||||||
/* Make it definitely odd. */
|
/* Make sure that we're always greater than 4. */
|
||||||
seed |= 1;
|
seed = (seed + 4) | 1;
|
||||||
|
|
||||||
while (!is_prime (seed))
|
while (!is_prime (seed))
|
||||||
seed += 2;
|
seed += 2;
|
||||||
|
Loading…
Reference in New Issue
Block a user