]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (bsd) improve checksum calculation [-Waddress-of-packed-member]
authorKarel Zak <kzak@redhat.com>
Wed, 22 May 2019 15:42:48 +0000 (17:42 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 22 May 2019 15:47:04 +0000 (17:47 +0200)
Let's keep compilers and static analyzers happy. The idea is to use
memcpy() to copy from buffer to variable and use all label as unsigned
char rather than vectorize by unsigned short.

Signed-off-by: Karel Zak <kzak@redhat.com>
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;
 }