summaryrefslogtreecommitdiff
path: root/lib/libc/db
diff options
context:
space:
mode:
authorMichael Shalayeff <mickey@cvs.openbsd.org>2000-10-03 18:16:49 +0000
committerMichael Shalayeff <mickey@cvs.openbsd.org>2000-10-03 18:16:49 +0000
commitbea4f5ff879d18264867bbb169b6e18da30c2dac (patch)
tree797653b3a1f910a4fce19219930a383a04e1d796 /lib/libc/db
parentfb49cff57b926c91afdec396760be62857b21a73 (diff)
bt_open.c: parenthesize - and & proper (from freebsd);
hash_bigkey.c: fix NULL dereference exposed on big bsize values; hash_buf.c: fix DEBUG1 cases to make them print, not crash; hash.3: document real default values for bsize and ffactor.
Diffstat (limited to 'lib/libc/db')
-rw-r--r--lib/libc/db/btree/bt_open.c12
-rw-r--r--lib/libc/db/hash/hash_bigkey.c6
-rw-r--r--lib/libc/db/hash/hash_buf.c10
-rw-r--r--lib/libc/db/man/hash.38
4 files changed, 19 insertions, 17 deletions
diff --git a/lib/libc/db/btree/bt_open.c b/lib/libc/db/btree/bt_open.c
index 62a62803d30..1ab8d163e03 100644
--- a/lib/libc/db/btree/bt_open.c
+++ b/lib/libc/db/btree/bt_open.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bt_open.c,v 1.6 1999/02/15 05:11:22 millert Exp $ */
+/* $OpenBSD: bt_open.c,v 1.7 2000/10/03 18:16:48 mickey Exp $ */
/*-
* Copyright (c) 1990, 1993, 1994
@@ -40,7 +40,7 @@
#if 0
static char sccsid[] = "@(#)bt_open.c 8.11 (Berkeley) 11/2/95";
#else
-static char rcsid[] = "$OpenBSD: bt_open.c,v 1.6 1999/02/15 05:11:22 millert Exp $";
+static char rcsid[] = "$OpenBSD: bt_open.c,v 1.7 2000/10/03 18:16:48 mickey Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -131,7 +131,7 @@ __bt_open(fname, flags, mode, openinfo, dflags)
*/
if (b.psize &&
(b.psize < MINPSIZE || b.psize > MAX_PAGE_OFFSET + 1 ||
- b.psize & sizeof(indx_t) - 1))
+ b.psize & (sizeof(indx_t) - 1) ))
goto einval;
/* Minimum number of keys per page; absolute minimum is 2. */
@@ -251,7 +251,7 @@ __bt_open(fname, flags, mode, openinfo, dflags)
if (m.magic != BTREEMAGIC || m.version != BTREEVERSION)
goto eftype;
if (m.psize < MINPSIZE || m.psize > MAX_PAGE_OFFSET + 1 ||
- m.psize & sizeof(indx_t) - 1)
+ m.psize & (sizeof(indx_t) - 1) )
goto eftype;
if (m.flags & ~SAVEMETA)
goto eftype;
@@ -284,8 +284,8 @@ __bt_open(fname, flags, mode, openinfo, dflags)
t->bt_psize = b.psize;
/* Set the cache size; must be a multiple of the page size. */
- if (b.cachesize && b.cachesize & b.psize - 1)
- b.cachesize += (~b.cachesize & b.psize - 1) + 1;
+ if (b.cachesize && b.cachesize & (b.psize - 1) )
+ b.cachesize += (~b.cachesize & (b.psize - 1) ) + 1;
if (b.cachesize < b.psize * MINCACHE)
b.cachesize = b.psize * MINCACHE;
diff --git a/lib/libc/db/hash/hash_bigkey.c b/lib/libc/db/hash/hash_bigkey.c
index 9e88d55deb5..4e5e236879c 100644
--- a/lib/libc/db/hash/hash_bigkey.c
+++ b/lib/libc/db/hash/hash_bigkey.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hash_bigkey.c,v 1.6 1999/02/15 05:11:24 millert Exp $ */
+/* $OpenBSD: hash_bigkey.c,v 1.7 2000/10/03 18:16:48 mickey Exp $ */
/*-
* Copyright (c) 1990, 1993, 1994
@@ -40,7 +40,7 @@
#if 0
static char sccsid[] = "@(#)hash_bigkey.c 8.3 (Berkeley) 5/31/94";
#else
-static char rcsid[] = "$OpenBSD: hash_bigkey.c,v 1.6 1999/02/15 05:11:24 millert Exp $";
+static char rcsid[] = "$OpenBSD: hash_bigkey.c,v 1.7 2000/10/03 18:16:48 mickey Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -256,7 +256,7 @@ __big_delete(hashp, bufp)
bufp->flags |= BUF_MOD;
if (rbufp)
__free_ovflpage(hashp, rbufp);
- if (last_bfp != rbufp)
+ if (last_bfp && last_bfp != rbufp)
__free_ovflpage(hashp, last_bfp);
hashp->NKEYS--;
diff --git a/lib/libc/db/hash/hash_buf.c b/lib/libc/db/hash/hash_buf.c
index def35a5ede1..45dfbaaca49 100644
--- a/lib/libc/db/hash/hash_buf.c
+++ b/lib/libc/db/hash/hash_buf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hash_buf.c,v 1.7 1999/02/15 05:11:24 millert Exp $ */
+/* $OpenBSD: hash_buf.c,v 1.8 2000/10/03 18:16:48 mickey Exp $ */
/*-
* Copyright (c) 1990, 1993, 1994
@@ -40,7 +40,7 @@
#if 0
static char sccsid[] = "@(#)hash_buf.c 8.5 (Berkeley) 7/15/94";
#else
-static char rcsid[] = "$OpenBSD: hash_buf.c,v 1.7 1999/02/15 05:11:24 millert Exp $";
+static char rcsid[] = "$OpenBSD: hash_buf.c,v 1.8 2000/10/03 18:16:48 mickey Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@@ -266,22 +266,22 @@ newbuf(hashp, addr, prev_bp)
/* Now assign this buffer */
bp->addr = addr;
+ bp->ovfl = NULL;
#ifdef DEBUG1
(void)fprintf(stderr, "NEWBUF1: %d->ovfl was %d is now %d\n",
bp->addr, (bp->ovfl ? bp->ovfl->addr : 0), 0);
#endif
- bp->ovfl = NULL;
if (prev_bp) {
/*
* If prev_bp is set, this is an overflow page, hook it in to
* the buffer overflow links.
*/
+ prev_bp->ovfl = bp;
#ifdef DEBUG1
(void)fprintf(stderr, "NEWBUF2: %d->ovfl was %d is now %d\n",
- prev_bp->addr, (prev_bp->ovfl ? bp->ovfl->addr : 0),
+ prev_bp->addr, (prev_bp->ovfl ? prev_bp->ovfl->addr : 0),
(bp ? bp->addr : 0));
#endif
- prev_bp->ovfl = bp;
bp->flags = 0;
} else
bp->flags = BUF_BUCKET;
diff --git a/lib/libc/db/man/hash.3 b/lib/libc/db/man/hash.3
index 3aeab2ff800..5b78ded89e6 100644
--- a/lib/libc/db/man/hash.3
+++ b/lib/libc/db/man/hash.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: hash.3,v 1.10 2000/04/18 02:31:35 aaron Exp $
+.\" $OpenBSD: hash.3,v 1.11 2000/10/03 18:16:48 mickey Exp $
.\" $NetBSD: hash.3,v 1.6 1996/05/03 21:26:50 cgd Exp $
.\"
.\" Copyright (c) 1997, Phillip F Knaack. All rights reserved.
@@ -87,7 +87,8 @@ The elements of this structure are as follows:
.Bl -tag -width XXXXXX -offset indent
.It Fa bsize
.Fa bsize
-defines the hash table bucket size, and is, by default, 256 bytes.
+defines the hash table bucket size, and is, by default,
+the block size of the underlying filesystem.
It may be preferable to increase the page size for disk-resident tables
and tables with large data items.
.It Fa ffactor
@@ -95,7 +96,8 @@ and tables with large data items.
indicates a desired density within the hash table.
It is an approximation of the number of keys allowed to accumulate in any
one bucket, determining when the hash table grows or shrinks.
-The default value is 8.
+The default value is the same as
+.Fa bsize .
.It Fa nelem
.Fa nelem
is an estimate of the final size of the hash table.