From 870872aa8fa9489f2f3b7be0026776ee2a54dad0 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Tue, 20 Dec 2011 21:41:11 +0000 Subject: 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. --- apropos_db.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'apropos_db.c') 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++)) -- cgit