OSDN Git Service

Fix some strict-aliasing violations.
authorPeter Jones <pjones@redhat.com>
Mon, 13 Jul 2015 19:41:27 +0000 (15:41 -0400)
committerPeter Jones <pjones@redhat.com>
Mon, 13 Jul 2015 19:46:14 +0000 (15:46 -0400)
GCC seems to think there are some violations of the strict aliasing
rules; making them char * instead of uintN_t * causes the rules to be
different, and that makes them okay.

Resolves #25.

Signed-off-by: Peter Jones <pjones@redhat.com>
Make.defaults
src/dp-media.c
src/dp-message.c

index fee6b41..cc2baa9 100644 (file)
@@ -12,7 +12,8 @@ ARCH = $(shell uname -m)
 clang_cflags =
 gcc_cflags = -Wmaybe-uninitialized
 cflags := $(CFLAGS) \
-       -Wall -Wsign-compare -std=gnu11 -fshort-wchar -fPIC \
+       -Werror -Wall -Wsign-compare -Wstrict-aliasing \
+       -std=gnu11 -fshort-wchar -fPIC \
        -fvisibility=hidden \
        -D_GNU_SOURCE -I${TOPDIR}/src/include/efivar/ \
        $(if $(filter $(CC),clang),$(clang_cflags),) \
index a677204..ac09b3e 100644 (file)
@@ -36,7 +36,7 @@ _format_media_dn(char *buf, size_t size, const_efidp dp)
                case EFIDP_HD_SIGNATURE_MBR:
                        off += format(buf, size, off,
                                      "MBR,0x%"PRIu32",0x%"PRIx64",0x%"PRIx64")",
-                                     *(uint32_t *)dp->hd.signature,
+                                     *(char *)dp->hd.signature,
                                      dp->hd.start, dp->hd.size);
                        break;
                case EFIDP_HD_SIGNATURE_GUID:
index 90ff247..06d3bb6 100644 (file)
@@ -574,16 +574,16 @@ efidp_make_ipv4(uint8_t *buf, ssize_t size, uint32_t local, uint32_t remote,
                                        EFIDP_MSG_IPv4, sizeof (*ipv4));
        ssize_t req = sizeof (*ipv4);
        if (size && sz == req) {
-               *((uint32_t *)ipv4->local_ipv4_addr) = htonl(local);
-               *((uint32_t *)ipv4->remote_ipv4_addr) = htonl(remote);
+               *((char *)ipv4->local_ipv4_addr) = htonl(local);
+               *((char *)ipv4->remote_ipv4_addr) = htonl(remote);
                ipv4->local_port = htons(local_port);
                ipv4->remote_port = htons(remote_port);
                ipv4->protocol = htons(protocol);
                ipv4->static_ip_addr = 0;
                if (is_static)
                        ipv4->static_ip_addr = 1;
-               *((uint32_t *)ipv4->gateway) = htonl(gateway);
-               *((uint32_t *)ipv4->netmask) = htonl(netmask);
+               *((char *)ipv4->gateway) = htonl(gateway);
+               *((char *)ipv4->netmask) = htonl(netmask);
        }
        return sz;
 }