summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorKarel Zak2019-05-22 17:42:48 +0200
committerKarel Zak2019-05-22 17:42:48 +0200
commit1a56f15b0fe047dfd85fa1a7aaddcc8504e403a6 (patch)
tree02ad3b4e45b6d6821fd9d2fccf4b0d92ec106a28 /include
parentinclude/c: use __has_attribute (diff)
downloadkernel-qcow2-util-linux-1a56f15b0fe047dfd85fa1a7aaddcc8504e403a6.tar.gz
kernel-qcow2-util-linux-1a56f15b0fe047dfd85fa1a7aaddcc8504e403a6.tar.xz
kernel-qcow2-util-linux-1a56f15b0fe047dfd85fa1a7aaddcc8504e403a6.zip
libfdisk: (sgi) 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 uint32_t. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'include')
-rw-r--r--include/pt-sgi.h17
1 files changed, 11 insertions, 6 deletions
diff --git a/include/pt-sgi.h b/include/pt-sgi.h
index 547b37a87..5d6b68f13 100644
--- a/include/pt-sgi.h
+++ b/include/pt-sgi.h
@@ -93,15 +93,20 @@ struct sgi_disklabel {
static inline uint32_t sgi_pt_checksum(struct sgi_disklabel *label)
{
- int i;
- uint32_t *ptr = (uint32_t *) label;
+ int count;
uint32_t sum = 0;
+ unsigned char *ptr = (unsigned char *) label;
- i = sizeof(*label) / sizeof(*ptr);
+ count = sizeof(*label) / sizeof(uint32_t);
+ ptr += sizeof(uint32_t) * (count - 1);
- while (i) {
- i--;
- sum -= be32_to_cpu(ptr[i]);
+ while (count--) {
+ uint32_t val;
+
+ memcpy(&val, ptr, sizeof(uint32_t));
+ sum -= be32_to_cpu(val);
+
+ ptr -= sizeof(uint32_t);
}
return sum;