From: Ingo Schwarze <schwarze@usta.de>
To: tech@mdocml.bsd.lv
Subject: Re: Do not cast void pointers to pointers requiring alignment.
Date: Tue, 20 Dec 2011 17:47:39 +0100 [thread overview]
Message-ID: <20111220164739.GA10043@iris.usta.de> (raw)
In-Reply-To: <4EF06A3F.3010801@bsd.lv>
Hi Kristaps,
Kristaps Dzonsons wrote on Tue, Dec 20, 2011 at 11:58:07AM +0100:
> Is it easier to apply this or wait for the patch being reviewed by
> millert@? Whichever's more convenient for you.
I guess i'll apply it unless millert@ provides feedback before
we agree on it.
> However, I don't like the assertions in this code. A bad database
> shouldn't result in assertions (except the internal hashtable, as
> it's a programmatic matter).
I fully agree with that, but there are no assertions of the kind you
seem to suspect.
> All of these areas (index_prune(), index_read(), etc.), are built
> with failure handlers when break;ing or return badly. Can you
> modify the patch to use these instead?
That's already the case.
Yours,
Ingo
>>@@ -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);
>> }
>>
No assertion here, checks are above (unchanged).
>>@@ -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++))
The key is not stored in the database but is just the record number in
the file, so this asserts against internal malfunctioning of recno(3).
>>@@ -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);
Assert against hash mishandling.
>>@@ -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. */
>>
Assert against internal recno(3) errors, see above.
>>@@ -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;
>>+ }
Against hash mishandling, see above.
--
To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv
next prev parent reply other threads:[~2011-12-20 16:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-20 1:17 Ingo Schwarze
2011-12-20 10:58 ` Kristaps Dzonsons
2011-12-20 16:47 ` Ingo Schwarze [this message]
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=20111220164739.GA10043@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).