[FFmpeg-devel] [PATCH 2/2] avformat/rtpproto: fix strict aliasing violations with sockaddr

Michael Niedermayer michaelni at gmx.at
Fri Sep 12 01:52:39 CEST 2014


Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
 libavformat/rtpproto.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c
index a8cbd97..62f77da 100644
--- a/libavformat/rtpproto.c
+++ b/libavformat/rtpproto.c
@@ -130,23 +130,26 @@ static int compare_addr(const struct sockaddr_storage *a,
 
 static int get_port(const struct sockaddr_storage *ss)
 {
+    sockaddr_union ssu = (sockaddr_union){.storage = *ss};
     if (ss->ss_family == AF_INET)
-        return ntohs(((const struct sockaddr_in *)ss)->sin_port);
+        return ntohs(ssu.in.sin_port);
 #if HAVE_STRUCT_SOCKADDR_IN6
     if (ss->ss_family == AF_INET6)
-        return ntohs(((const struct sockaddr_in6 *)ss)->sin6_port);
+        return ntohs(ssu.in6.sin6_port);
 #endif
     return 0;
 }
 
 static void set_port(struct sockaddr_storage *ss, int port)
 {
+    sockaddr_union ssu = (sockaddr_union){.storage = *ss};
     if (ss->ss_family == AF_INET)
-        ((struct sockaddr_in *)ss)->sin_port = htons(port);
+        ssu.in.sin_port = htons(port);
 #if HAVE_STRUCT_SOCKADDR_IN6
     else if (ss->ss_family == AF_INET6)
-        ((struct sockaddr_in6 *)ss)->sin6_port = htons(port);
+        ssu.in6.sin6_port = htons(port);
 #endif
+    *ss = ssu.storage;
 }
 
 static int rtp_check_source_lists(RTPContext *s, struct sockaddr_storage *source_addr_ptr)
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list