Source-Changes-D archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: CVS commit: src/sys/arch/atari/stand/installboot
Date: Sat, 15 Nov 2014 13:43:16 +0900
From: Izumi Tsutsui <tsutsui%ceres.dti.ne.jp@localhost>
- uint16_t sum;
+ union {
+ struct bootblock *bbp;
+ uint16_t *word; /* to fill cksum word */
+ } bbsec;
...
- sum = 0;
- memcpy(bb->bb_xxboot + 255 * sizeof(sum), &sum, sizeof(sum));
- sum = 0x1234 - abcksum(bb->bb_xxboot);
- memcpy(bb->bb_xxboot + 255 * sizeof(sum), &sum, sizeof(sum));
+ bbsec.bbp = bb;
+ bbsec.word[255] = 0;
+ bbsec.word[255] = 0x1234 - abcksum(bb->bb_xxboot);
Um, that has the same issue as the original code, no? It still refers
to the content of the struct bootblock object by two different types,
struct bootblock and uint16_t -- passing the pointer through a union
doesn't change that.
What's wrong with the memcpy?
If you don't like the way the memcpy code looks, you could write
set16(bb->bb_xxboot, 255, 0);
set16(bb->bb_xxboot, 255, 0x1234 - abcksum(bb->bb_xxboot));
void
set16(void *p, size_t off, uint16_t v)
{
memcpy((uint8_t *)p + off*sizeof(uint16_t), &v, sizeof v);
}
I don't see any byte ordering issues here that weren't present before.
Home |
Main Index |
Thread Index |
Old Index