]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - libfdisk/src/bsd.c
libfdisk: (bsd) improve checksum calculation [-Waddress-of-packed-member]
[thirdparty/util-linux.git] / libfdisk / src / bsd.c
index 90b44b9639f2c170a847739f84f35ae4f0467c0e..4e05bb3288c7bffe7f9ddba7994999578131cbc6 100644 (file)
@@ -736,13 +736,20 @@ done:
 
 static unsigned short bsd_dkcksum (struct bsd_disklabel *lp)
 {
-       unsigned short *start, *end;
+       unsigned char *ptr, *end;
        unsigned short sum = 0;
 
-       start = (unsigned short *) lp;
-       end = (unsigned short *) &lp->d_partitions[lp->d_npartitions];
-       while (start < end)
-               sum ^= *start++;
+       ptr = (unsigned char *) lp;
+       end = (unsigned char *) &lp->d_partitions[lp->d_npartitions];
+
+       while (ptr < end) {
+               unsigned short val;
+
+               memcpy(&val, ptr, sizeof(unsigned short));
+               sum ^= val;
+
+               ptr += sizeof(unsigned short);
+       }
        return sum;
 }