summaryrefslogtreecommitdiffstats
path: root/mandocdb.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 /mandocdb.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 'mandocdb.c')
-rw-r--r--mandocdb.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/mandocdb.c b/mandocdb.c
index eacc1009..3dd84795 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -525,6 +525,7 @@ index_merge(const struct of *of, struct mparse *mp,
struct mdoc *mdoc;
struct man *man;
const char *fn, *msec, *mtitle, *arch;
+ uint64_t mask;
size_t sv;
unsigned seq;
struct db_val vbuf;
@@ -655,7 +656,9 @@ index_merge(const struct of *of, struct mparse *mp,
seq = R_FIRST;
while (0 == (ch = (*hash->seq)(hash, &key, &val, seq))) {
seq = R_NEXT;
- vbuf.mask = htobe64(*(uint64_t *)val.data);
+ assert(sizeof(uint64_t) == val.size);
+ memcpy(&mask, val.data, val.size);
+ vbuf.mask = htobe64(mask);
val.size = sizeof(struct db_val);
val.data = &vbuf;
dbt_put(db, dbf, &key, &val);
@@ -708,7 +711,8 @@ index_prune(const struct of *ofile, DB *db, const char *dbf,
seq = R_FIRST;
while (0 == (ch = (*idx->seq)(idx, &key, &val, seq))) {
seq = R_NEXT;
- *maxrec = *(recno_t *)key.data;
+ assert(sizeof(recno_t) == key.size);
+ memcpy(maxrec, key.data, key.size);
/* Deleted records are zero-sized. Skip them. */
@@ -1068,6 +1072,7 @@ pmdoc_Sh(MDOC_ARGS)
static void
hash_put(DB *db, const struct buf *buf, uint64_t mask)
{
+ uint64_t oldmask;
DBT key, val;
int rc;
@@ -1080,8 +1085,11 @@ hash_put(DB *db, const struct buf *buf, uint64_t mask)
if ((rc = (*db->get)(db, &key, &val, 0)) < 0) {
perror("hash");
exit((int)MANDOCLEVEL_SYSERR);
- } else if (0 == rc)
- mask |= *(uint64_t *)val.data;
+ } else if (0 == rc) {
+ assert(sizeof(uint64_t) == val.size);
+ memcpy(&oldmask, val.data, val.size);
+ mask |= oldmask;
+ }
val.data = &mask;
val.size = sizeof(uint64_t);