From 04d0701ea8d031c1392aaa77b0faf03f99d1c7a0 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 22 May 2019 17:42:48 +0200 Subject: 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 --- libfdisk/src/bsd.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'libfdisk/src') 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; } -- cgit v1.2.3-55-g7522