summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2019-05-22 17:42:48 +0200
committerKarel Zak2019-05-22 17:47:04 +0200
commit04d0701ea8d031c1392aaa77b0faf03f99d1c7a0 (patch)
tree8b8a79060feb40e463d1655ad656ea1254c1c376
parentlibblkid: (silicon raid) improve checksum calculation [-Waddress-of-packed-me... (diff)
downloadkernel-qcow2-util-linux-04d0701ea8d031c1392aaa77b0faf03f99d1c7a0.tar.gz
kernel-qcow2-util-linux-04d0701ea8d031c1392aaa77b0faf03f99d1c7a0.tar.xz
kernel-qcow2-util-linux-04d0701ea8d031c1392aaa77b0faf03f99d1c7a0.zip
libfdisk: (bsd) improve checksum calculation [-Waddress-of-packed-member]
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>
-rw-r--r--libfdisk/src/bsd.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/libfdisk/src/bsd.c b/libfdisk/src/bsd.c
index 90b44b963..4e05bb328 100644
--- a/libfdisk/src/bsd.c
+++ b/libfdisk/src/bsd.c
@@ -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;
}