summaryrefslogtreecommitdiffstats
path: root/apropos_db.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2011-12-20 21:41:11 +0000
committerIngo Schwarze <schwarze@openbsd.org>2011-12-20 21:41:11 +0000
commit870872aa8fa9489f2f3b7be0026776ee2a54dad0 (patch)
tree088e810a0353ba103aa705d308e8832daf968923 /apropos_db.c
parent8b085aba08a98619780dc5406fca3cf10bb7cdb6 (diff)
downloadmandoc-870872aa8fa9489f2f3b7be0026776ee2a54dad0.tar.gz
Do not cast void pointers to pointers requiring alignment.
This makes mandocdb(8)/apropos(1) work on strict alignment architectures. Basic way to fix this confirmed by deraadt@ and kettenis@, thanks. ok kristaps@ This now works on both sparc64 and i386, but note that the binary database format is still machine-dependent.
Diffstat (limited to 'apropos_db.c')
-rw-r--r--apropos_db.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/apropos_db.c b/apropos_db.c
index f50e91f2..79350f45 100644
--- a/apropos_db.c
+++ b/apropos_db.c
@@ -171,7 +171,7 @@ btree_read(const DBT *k, const DBT *v,
const struct mchars *mc,
struct db_val *dbv, char **buf)
{
- const struct db_val *vp;
+ struct db_val raw_dbv;
/* Are our sizes sane? */
if (k->size < 2 || sizeof(struct db_val) != v->size)
@@ -181,10 +181,10 @@ btree_read(const DBT *k, const DBT *v,
if ('\0' != ((const char *)k->data)[(int)k->size - 1])
return(0);
- vp = v->data;
norm_string((const char *)k->data, mc, buf);
- dbv->rec = betoh32(vp->rec);
- dbv->mask = betoh64(vp->mask);
+ memcpy(&raw_dbv, v->data, v->size);
+ dbv->rec = betoh32(raw_dbv.rec);
+ dbv->mask = betoh64(raw_dbv.mask);
return(1);
}
@@ -380,7 +380,8 @@ index_read(const DBT *key, const DBT *val, int index,
return(0);
cp = val->data;
- rec->res.rec = *(recno_t *)key->data;
+ assert(sizeof(recno_t) == key->size);
+ memcpy(&rec->res.rec, key->data, key->size);
rec->res.volume = index;
if ('d' == (type = *cp++))