summaryrefslogtreecommitdiff
path: root/libhurd-ihash
diff options
context:
space:
mode:
authormarcus <marcus>2003-08-17 04:16:09 +0000
committermarcus <marcus>2003-08-17 04:16:09 +0000
commit99041316540944700bd70b21a26adeaacd974b47 (patch)
tree66ad928bc44d78c39cf4736fb1ac45685c5adcff /libhurd-ihash
parent450b766740534d27c3da52de1226d5ce3c01ceed (diff)
Fix prime table types. Improve overflow check when finding the next prime
number.
Diffstat (limited to 'libhurd-ihash')
-rw-r--r--libhurd-ihash/ihash.c26
-rw-r--r--libhurd-ihash/ihash.h1
2 files changed, 16 insertions, 11 deletions
diff --git a/libhurd-ihash/ihash.c b/libhurd-ihash/ihash.c
index dfaa052..f45d94a 100644
--- a/libhurd-ihash/ihash.c
+++ b/libhurd-ihash/ihash.c
@@ -24,6 +24,7 @@
#include <string.h>
#include <stdlib.h>
#include <limits.h>
+#include <stdint.h>
#include <assert.h>
#include <hurd/ihash.h>
@@ -31,7 +32,7 @@
/* The odd prime numbers greater than twice the last and less than
2^40 (nobody needs more than 640 GB of memory). */
-static const unsigned int ihash_sizes[] =
+static const uint64_t ihash_sizes[] =
{
3,
7,
@@ -62,15 +63,15 @@ static const unsigned int ihash_sizes[] =
359339171,
718678369,
1437356741,
- 2874713497,
- 5749427029,
- 11498854069,
- 22997708177,
- 45995416409,
- 91990832831,
- 183981665689,
- 367963331389,
- 735926662813
+ UINT64_C (2874713497),
+ UINT64_C (5749427029),
+ UINT64_C (11498854069),
+ UINT64_C (22997708177),
+ UINT64_C (45995416409),
+ UINT64_C (91990832831),
+ UINT64_C (183981665689),
+ UINT64_C (367963331389),
+ UINT64_C (735926662813)
};
@@ -282,7 +283,10 @@ hurd_ihash_add (hurd_ihash_t ht, hurd_ihash_key_t key,
for (i = 0; i < ihash_nsizes; i++)
if (ihash_sizes[i] > old_ht.size)
break;
- if (i == ihash_nsizes)
+ if (i == ihash_nsizes
+ || ihash_sizes[i] > SIZE_MAX / sizeof (hurd_ihash_value_t)
+ || ihash_sizes[i] > SIZE_MAX / sizeof (hurd_ihash_key_t)
+ || ihash_sizes[i] > SIZE_MAX / sizeof (hurd_ihash_locp_t *))
return ENOMEM; /* Surely will be true momentarily. */
ht->size = ihash_sizes[i];
diff --git a/libhurd-ihash/ihash.h b/libhurd-ihash/ihash.h
index 3d74ac5..3dc9d98 100644
--- a/libhurd-ihash/ihash.h
+++ b/libhurd-ihash/ihash.h
@@ -1,3 +1,4 @@
+typedef int error_t;
/* ihash.h - Integer keyed hash table interface.
Copyright (C) 1995, 2003 Free Software Foundation, Inc.
Written by Miles Bader <miles@gnu.org>.