From: Ingo Schwarze <schwarze@usta.de>
To: tech@mdocml.bsd.lv
Subject: Do not cast void pointers to pointers requiring alignment.
Date: Tue, 20 Dec 2011 02:17:31 +0100 [thread overview]
Message-ID: <20111220011731.GB22316@iris.usta.de> (raw)
You want this, too?
Ingo
----- Forwarded message from Ingo Schwarze <schwarze@cvs.openbsd.org> -----
From: Ingo Schwarze <schwarze@cvs.openbsd.org>
Date: Mon, 19 Dec 2011 17:41:24 -0700 (MST)
To: source-changes@cvs.openbsd.org
Subject: CVS: cvs.openbsd.org: src
CVSROOT: /cvs
Module name: src
Changes by: schwarze@cvs.openbsd.org 2011/12/19 17:41:24
Modified files:
usr.bin/mandoc : apropos_db.c mandocdb.c
Log message:
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.
This now works on both sparc64 and i386, but note that the binary
database format is still machine-dependent.
----- End forwarded message -----
Index: apropos_db.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/apropos_db.c,v
retrieving revision 1.15
diff -u -p -r1.15 apropos_db.c
--- apropos_db.c 19 Dec 2011 02:26:33 -0000 1.15
+++ apropos_db.c 20 Dec 2011 00:18:56 -0000
@@ -160,7 +160,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)
@@ -170,10 +170,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);
}
@@ -369,7 +369,8 @@ index_read(const DBT *key, const DBT *va
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++))
Index: mandocdb.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/mandocdb.c,v
retrieving revision 1.26
diff -u -p -r1.26 mandocdb.c
--- mandocdb.c 19 Dec 2011 02:26:33 -0000 1.26
+++ mandocdb.c 20 Dec 2011 00:18:58 -0000
@@ -518,6 +518,7 @@ index_merge(const struct of *of, struct
struct mdoc *mdoc;
struct man *man;
const char *fn, *msec, *mtitle, *arch;
+ uint64_t mask;
size_t sv;
unsigned seq;
struct db_val vbuf;
@@ -648,7 +649,9 @@ index_merge(const struct of *of, struct
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);
@@ -701,7 +704,8 @@ index_prune(const struct of *ofile, DB *
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. */
@@ -1061,6 +1065,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;
@@ -1073,8 +1078,11 @@ hash_put(DB *db, const struct buf *buf,
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);
--
To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv
next reply other threads:[~2011-12-20 1:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-20 1:17 Ingo Schwarze [this message]
2011-12-20 10:58 ` Kristaps Dzonsons
2011-12-20 16:47 ` Ingo Schwarze
2011-12-20 16:54 ` Kristaps Dzonsons
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111220011731.GB22316@iris.usta.de \
--to=schwarze@usta.de \
--cc=tech@mdocml.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).