From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from scc-mailout.scc.kit.edu (scc-mailout.scc.kit.edu [129.13.185.202]) by krisdoz.my.domain (8.14.5/8.14.5) with ESMTP id pBKGlfWk003050 for ; Tue, 20 Dec 2011 11:47:42 -0500 (EST) Received: from hekate.usta.de (asta-nat.asta.uni-karlsruhe.de [172.22.63.82]) by scc-mailout-02.scc.kit.edu with esmtp (Exim 4.72 #1) id 1Rd2qq-0002WG-EO; Tue, 20 Dec 2011 17:47:40 +0100 Received: from donnerwolke.usta.de ([172.24.96.3]) by hekate.usta.de with esmtp (Exim 4.72) (envelope-from ) id 1Rd2qq-0000rJ-Cy for tech@mdocml.bsd.lv; Tue, 20 Dec 2011 17:47:40 +0100 Received: from iris.usta.de ([172.24.96.5] helo=usta.de) by donnerwolke.usta.de with esmtp (Exim 4.72) (envelope-from ) id 1Rd2qq-0001C9-BT for tech@mdocml.bsd.lv; Tue, 20 Dec 2011 17:47:40 +0100 Received: from schwarze by usta.de with local (Exim 4.72) (envelope-from ) id 1Rd2qq-0007f9-1v for tech@mdocml.bsd.lv; Tue, 20 Dec 2011 17:47:40 +0100 Date: Tue, 20 Dec 2011 17:47:39 +0100 From: Ingo Schwarze To: tech@mdocml.bsd.lv Subject: Re: Do not cast void pointers to pointers requiring alignment. Message-ID: <20111220164739.GA10043@iris.usta.de> References: <20111220011731.GB22316@iris.usta.de> <4EF06A3F.3010801@bsd.lv> X-Mailinglist: mdocml-tech Reply-To: tech@mdocml.bsd.lv MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4EF06A3F.3010801@bsd.lv> User-Agent: Mutt/1.5.21 (2010-09-15) 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