From: Mike Brady Date: Wed, 7 Mar 2018 08:58:23 +0000 (+0000) Subject: Begin to avoid strict aliasing violations -- not finished yet. X-Git-Tag: 3.2d29~40 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a7d82ae82340f993448b3bef2f2134981a895754;p=thirdparty%2Fshairport-sync.git Begin to avoid strict aliasing violations -- not finished yet. --- diff --git a/common.c b/common.c index 9044041b..bce72fa8 100644 --- 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); +} diff --git a/common.h b/common.h index 89e15259..894ecf47 100644 --- 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 cb38c4bb..25222423 100644 --- 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;