From: Karel Zak Date: Wed, 22 May 2019 15:42:48 +0000 (+0200) Subject: libfdisk: (bsd) improve checksum calculation [-Waddress-of-packed-member] X-Git-Tag: v2.34-rc2~36 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=04d0701ea8d031c1392aaa77b0faf03f99d1c7a0;p=thirdparty%2Futil-linux.git 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 --- diff --git a/libfdisk/src/bsd.c b/libfdisk/src/bsd.c index 90b44b9639..4e05bb3288 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; }