]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - include/pt-sgi.h
libfdisk: (sgi) improve checksum calculation [-Waddress-of-packed-member]
[thirdparty/util-linux.git] / include / pt-sgi.h
index 547b37a872ae7a3c6592c3c5b89b716f24ecdb8c..5d6b68f1343dc9a7787a7e88f09aae014ad56874 100644 (file)
@@ -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;