ae5d40
commit 25dcf01e340d85bcdbe7b3c24eac7fe1ce7ea0c2
ae5d40
Author: Miroslav Lichvar <mlichvar@redhat.com>
ae5d40
Date:   Wed Mar 10 17:05:55 2021 +0100
ae5d40
ae5d40
    Avoid unaligned pointers to packed members.
ae5d40
    
ae5d40
    This fixes "taking address of packed member ... may result in an
ae5d40
    unaligned pointer value [-Waddress-of-packed-member]" warnings from gcc.
ae5d40
    
ae5d40
    Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
ae5d40
ae5d40
diff --git a/clock.c b/clock.c
ae5d40
index 7005636..f88df58 100644
ae5d40
--- a/clock.c
ae5d40
+++ b/clock.c
ae5d40
@@ -350,6 +350,7 @@ static int clock_management_fill_response(struct clock *c, struct port *p,
ae5d40
 	struct time_status_np *tsn;
ae5d40
 	struct tlv_extra *extra;
ae5d40
 	struct PTPText *text;
ae5d40
+	uint16_t duration;
ae5d40
 	int datalen = 0;
ae5d40
 
ae5d40
 	extra = tlv_extra_alloc();
ae5d40
@@ -452,7 +453,8 @@ static int clock_management_fill_response(struct clock *c, struct port *p,
ae5d40
 			break;
ae5d40
 		}
ae5d40
 		sen = (struct subscribe_events_np *)tlv->data;
ae5d40
-		clock_get_subscription(c, req, sen->bitmask, &sen->duration);
ae5d40
+		clock_get_subscription(c, req, sen->bitmask, &duration);
ae5d40
+		memcpy(&sen->duration, &duration, sizeof(sen->duration));
ae5d40
 		datalen = sizeof(*sen);
ae5d40
 		break;
ae5d40
 	case TLV_SYNCHRONIZATION_UNCERTAIN_NP:
ae5d40
diff --git a/msg.c b/msg.c
ae5d40
index c4516ad..dcb397c 100644
ae5d40
--- a/msg.c
ae5d40
+++ b/msg.c
ae5d40
@@ -19,6 +19,7 @@
ae5d40
 #include <arpa/inet.h>
ae5d40
 #include <errno.h>
ae5d40
 #include <malloc.h>
ae5d40
+#include <stdlib.h>
ae5d40
 #include <string.h>
ae5d40
 #include <time.h>
ae5d40
 
ae5d40
@@ -36,8 +37,8 @@ int assume_two_step = 0;
ae5d40
 
ae5d40
 struct message_storage {
ae5d40
 	unsigned char reserved[MSG_HEADROOM];
ae5d40
-	struct ptp_message msg;
ae5d40
-} PACKED;
ae5d40
+	struct ptp_message msg __attribute__((aligned (8)));
ae5d40
+};
ae5d40
 
ae5d40
 static TAILQ_HEAD(msg_pool, ptp_message) msg_pool = TAILQ_HEAD_INITIALIZER(msg_pool);
ae5d40
 
ae5d40
diff --git a/tlv.c b/tlv.c
ae5d40
index 879bb7e..98ef6e1 100644
ae5d40
--- a/tlv.c
ae5d40
+++ b/tlv.c
ae5d40
@@ -67,7 +67,7 @@ static void timestamp_net2host(struct Timestamp *t)
ae5d40
 	NTOHL(t->nanoseconds);
ae5d40
 }
ae5d40
 
ae5d40
-static uint16_t flip16(uint16_t *p)
ae5d40
+static uint16_t flip16(void *p)
ae5d40
 {
ae5d40
 	uint16_t v;
ae5d40
 	memcpy(&v, p, sizeof(v));
ae5d40
@@ -76,7 +76,7 @@ static uint16_t flip16(uint16_t *p)
ae5d40
 	return v;
ae5d40
 }
ae5d40
 
ae5d40
-static int64_t host2net64_unaligned(int64_t *p)
ae5d40
+static int64_t host2net64_unaligned(void *p)
ae5d40
 {
ae5d40
 	int64_t v;
ae5d40
 	memcpy(&v, p, sizeof(v));
ae5d40
@@ -85,7 +85,7 @@ static int64_t host2net64_unaligned(int64_t *p)
ae5d40
 	return v;
ae5d40
 }
ae5d40
 
ae5d40
-static int64_t net2host64_unaligned(int64_t *p)
ae5d40
+static int64_t net2host64_unaligned(void *p)
ae5d40
 {
ae5d40
 	int64_t v;
ae5d40
 	memcpy(&v, p, sizeof(v));
ae5d40
diff --git a/util.h b/util.h
ae5d40
index 41e33d4..739c8fd 100644
ae5d40
--- a/util.h
ae5d40
+++ b/util.h
ae5d40
@@ -57,7 +57,7 @@ const char *ts_str(enum timestamp_type ts);
ae5d40
  */
ae5d40
 int addreq(enum transport_type type, struct address *a, struct address *b);
ae5d40
 
ae5d40
-static inline uint16_t align16(uint16_t *p)
ae5d40
+static inline uint16_t align16(void *p)
ae5d40
 {
ae5d40
 	uint16_t v;
ae5d40
 	memcpy(&v, p, sizeof(v));