]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Begin to avoid strict aliasing violations -- not finished yet.
authorMike Brady <mikebrady@eircom.net>
Wed, 7 Mar 2018 08:58:23 +0000 (08:58 +0000)
committerMike Brady <mikebrady@eircom.net>
Wed, 7 Mar 2018 08:58:23 +0000 (08:58 +0000)
common.c
common.h
rtp.c

index 9044041bc6a96e434ba378bcfcaa5153b6fb0dad..bce72fa81b3c2c15d2a323802e5b72a4fe63bbc7 100644 (file)
--- a/common.c
+++ b/common.c
@@ -968,3 +968,10 @@ void r64arrayinit() { ranarrayinit(); }
 uint64_t ranarray64u() { return (ranarrayval()); }
 
 int64_t ranarray64i() { return (ranarrayval() >> 1); }
+
+uint32_t nctohl(const char * p) {  // read 4 characters from the p and do ntohl on them
+  // this is to avoid possible aliasing violations
+  uint32_t holder;
+  memcpy(&holder,p,sizeof(holder));
+  return ntohl(holder);
+}
index 89e1525956eab21d23d13af06ba4026a50e68a8a..894ecf471e08c7fe25c51747f1d3b3b0c368d229 100644 (file)
--- a/common.h
+++ b/common.h
@@ -177,6 +177,9 @@ typedef struct {
 
 } shairport_cfg;
 
+
+uint32_t nctohl(const char * p); // read 4 characters from the p and do ntohl on them
+
 // true if Shairport Sync is supposed to be sending output to the output device, false otherwise
 
 int get_requested_connection_state_to_output();
diff --git a/rtp.c b/rtp.c
index cb38c4bb29b81914fb07a256e662cc8c9e53bc7f..25222423db4428d1ae2a33cb911c719ca8b7fe2a 100644 (file)
--- a/rtp.c
+++ b/rtp.c
@@ -221,12 +221,12 @@ void *rtp_control_receiver(void *arg) {
       */
       if (conn->local_to_remote_time_difference) { // need a time packet to be interchanged first...
 
-        remote_time_of_sync = (uint64_t)ntohl(*((uint32_t *)&packet[8])) << 32;
-        remote_time_of_sync += ntohl(*((uint32_t *)&packet[12]));
+        remote_time_of_sync = (uint64_t)nctohl(&packet[8]) << 32;
+        remote_time_of_sync += nctohl(&packet[12]);
 
         // debug(1,"Remote Sync Time: %0llx.",remote_time_of_sync);
 
-        sync_rtp_timestamp = monotonic_timestamp(ntohl(*((uint32_t *)&packet[16])), conn);
+        sync_rtp_timestamp = monotonic_timestamp(nctohl(&packet[16]), conn);
         
         // debug(1,"Sync timestamp is %u.",ntohl(*((uint32_t *)&packet[16])));
 
@@ -238,7 +238,7 @@ void *rtp_control_receiver(void *arg) {
         } else if (packet[0] &
                    0x10) { // only set latency if it's a packet just after a flush or resume
           int64_t rtp_timestamp_less_latency =
-              monotonic_timestamp(ntohl(*((uint32_t *)&packet[4])), conn);
+              monotonic_timestamp(nctohl(&packet[4]), conn);
           int64_t la = sync_rtp_timestamp - rtp_timestamp_less_latency + config.fixedLatencyOffset;
           if ((conn->maximum_latency) && (conn->maximum_latency < la))
             la = conn->maximum_latency;
@@ -460,14 +460,14 @@ void *rtp_timing_receiver(void *arg) {
         // distant_receive_time =
         // ((uint64_t)ntohl(*((uint32_t*)&packet[16])))<<32+ntohl(*((uint32_t*)&packet[20]));
 
-        distant_receive_time = (uint64_t)ntohl(*((uint32_t *)&packet[16])) << 32;
-        distant_receive_time += ntohl(*((uint32_t *)&packet[20]));
+        distant_receive_time = (uint64_t)nctohl(&packet[16]) << 32;
+        distant_receive_time += nctohl(&packet[20]);
 
         // distant_transmit_time =
         // ((uint64_t)ntohl(*((uint32_t*)&packet[24])))<<32+ntohl(*((uint32_t*)&packet[28]));
 
-        distant_transmit_time = (uint64_t)ntohl(*((uint32_t *)&packet[24])) << 32;
-        distant_transmit_time += ntohl(*((uint32_t *)&packet[28]));
+        distant_transmit_time = (uint64_t)nctohl(&packet[24]) << 32;
+        distant_transmit_time += nctohl(&packet[28]);
 
         processing_time = distant_transmit_time - distant_receive_time;