diff options
author | Markus Friedl <markus@cvs.openbsd.org> | 2003-10-31 11:10:42 +0000 |
---|---|---|
committer | Markus Friedl <markus@cvs.openbsd.org> | 2003-10-31 11:10:42 +0000 |
commit | adf9f7e21924d3bd00ef5563e04ceb1cb55090e2 (patch) | |
tree | 76a04ca5de11ed220633ec0b596383d832d7f512 /sys/kern | |
parent | e06eb564e5758b97b973946a00fc07ddc38795e0 (diff) |
allocate at least as much elements as requested in hashinit
fixes pr 3537, based on patch from daniel@nofsk.nofsk.au.eu.org
ok millert@, deraadt@, tedu@
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_subr.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/sys/kern/kern_subr.c b/sys/kern/kern_subr.c index 4b0c4105c9b..d9c4abba39a 100644 --- a/sys/kern/kern_subr.c +++ b/sys/kern/kern_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_subr.c,v 1.25 2003/07/21 22:44:50 tedu Exp $ */ +/* $OpenBSD: kern_subr.c,v 1.26 2003/10/31 11:10:41 markus Exp $ */ /* $NetBSD: kern_subr.c,v 1.15 1996/04/09 17:21:56 ragge Exp $ */ /* @@ -164,16 +164,14 @@ hashinit(elements, type, flags, hashmask) int elements, type, flags; u_long *hashmask; { - long hashsize; + u_long hashsize, i; LIST_HEAD(generic, generic) *hashtbl; - int i; if (elements <= 0) panic("hashinit: bad cnt"); - for (hashsize = 1; hashsize <= elements; hashsize <<= 1) + for (hashsize = 1; hashsize < elements; hashsize <<= 1) continue; - hashsize >>= 1; - hashtbl = malloc((u_long)hashsize * sizeof(*hashtbl), type, flags); + hashtbl = malloc(hashsize * sizeof(*hashtbl), type, flags); if (hashtbl == NULL) return NULL; for (i = 0; i < hashsize; i++) |