riastradh@ wrote:

> As is, there are obviously violations, but we have papered over them
> enough that GCC isn't smart enough to warn about them: the void * cast
> through abcksum

I'd like to hear your answer of my dumb question:
http://mail-index.netbsd.org/source-changes-d/2014/11/16/msg007354.html
>> Then why don't you guys also complain to fix existing abcksum() function
>> which is called at the suggested memcpy?

If you think the existing abcksum() is vaild, does this one
(adding a function which does the same as abcksum) satisfy you?
Or is it still better to revert all changes and put -fno-strict-aliasing?

--- installboot.c.orig  2014-11-16 22:38:39.000000000 +0900
+++ installboot.c       2014-11-22 23:40:36.000000000 +0900
@@ -56,6 +56,7 @@
 static void    usage(void);
 static void    oscheck(void);
 static u_int   abcksum(void *);
+static void    setabcksum(void *, u_int16_t);
 static void    setNVpref(void);
 static void    setIDEpar(u_int8_t *, size_t);
 static void    mkahdiboot(struct ahdi_root *, char *,
@@ -467,6 +468,7 @@
     struct disklabel *label, u_int magic)
 {
        int              fd;
+       u_int16_t cksum;
 
        memset(bb, 0, sizeof(*bb));
 
@@ -498,8 +500,9 @@
        setIDEpar(bb->bb_xxboot, sizeof(bb->bb_xxboot));
 
        /* set AHDI checksum */
-       *((u_int16_t *)bb->bb_xxboot + 255) = 0;
-       *((u_int16_t *)bb->bb_xxboot + 255) = 0x1234 - abcksum(bb->bb_xxboot);
+       setabcksum(bb->bb_xxboot, 0);
+       cksum = 0x1234 - abcksum(bb->bb_xxboot);
+       setabcksum(bb->bb_xxboot, cksum);
 
        if (verbose) {
                printf("Primary   boot loader: %s\n", xxb);
@@ -582,3 +585,11 @@
                sum += *st++;
        return(sum);
 }
+
+static void
+setabcksum(void *bs, u_int16_t sum)
+{
+       u_int16_t *cksum = (u_int16_t *)bs + 255;
+
+       *cksum = sum;
+}

---
Izumi Tsutsui

Reply via email to