Subject: Re: unusual panics on NetBSD/alpha 3.0_* and 4.0_BETA
To: None <port-alpha@NetBSD.org, tech-kern@NetBSD.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-kern
Date: 10/08/2006 12:21:44
>>         for (i = 0; i < num_sack_blks; i++, lp += 2) {
>>                 memcpy(&left, lp, sizeof(*lp));
>>                 memcpy(&right, lp + 1, sizeof(*lp));

I'm not sure whether this is the "anti-aliasing" David wrote of, but
this code is already broken (FSVO "broken") on any architecture where
an unaligned u_int32_t pointer cannot be represented (word-addressed
machines).

The right way to handle it (in this respect) would be something like

	char *lp;
	....
	for (i=0;i<num_sack_blks;i++,lp+=8) {
		memcpy(&left,lp,4);
		memcpy(&right,lp+4,4);
		....
	}

You could use sizeof(u_int32_t) and 2*sizeof(u_int32_t) instead of 4
and 8 if you prefer, and it arguably would be better because it would
insulate the code against architectures where char != octet.  (Of
course, whether we care about such is another question.  I prefer to be
safer than necessary, as a matter of forming good habits if nothing
else.)

/~\ The ASCII				der Mouse
\ / Ribbon Campaign
 X  Against HTML	       mouse@rodents.montreal.qc.ca
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B