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