[PATCH] rtp: Get rid of an "unitialized value" warning from Coverity.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Coverity warned that r was possibly being used without
initialization. The fix is to add pa_assert_not_reached()
to handle the case where the address family is invalid. I
also felt that using switch would be more appropriate here
than using ifs and else-ifs, which makes this patch a bit
larger. I also changed the memset() calls to pa_zero().
---
 src/modules/rtp/module-rtp-recv.c |   29 +++++++++++++++++++----------
 1 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/src/modules/rtp/module-rtp-recv.c b/src/modules/rtp/module-rtp-recv.c
index 412f4c3..3a349a6 100644
--- a/src/modules/rtp/module-rtp-recv.c
+++ b/src/modules/rtp/module-rtp-recv.c
@@ -445,18 +445,27 @@ static int mcast_socket(const struct sockaddr* sa, socklen_t salen) {
         goto fail;
     }
 
-    if (af == AF_INET) {
-        struct ip_mreq mr4;
-        memset(&mr4, 0, sizeof(mr4));
-        mr4.imr_multiaddr = ((const struct sockaddr_in*) sa)->sin_addr;
-        r = setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mr4, sizeof(mr4));
+    switch (af) {
+        case AF_INET: {
+            struct ip_mreq mr4;
+
+            pa_zero(mr4);
+            mr4.imr_multiaddr = ((const struct sockaddr_in*) sa)->sin_addr;
+            r = setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mr4, sizeof(mr4));
+            break;
+        }
 #ifdef HAVE_IPV6
-    } else {
-        struct ipv6_mreq mr6;
-        memset(&mr6, 0, sizeof(mr6));
-        mr6.ipv6mr_multiaddr = ((const struct sockaddr_in6*) sa)->sin6_addr;
-        r = setsockopt(fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mr6, sizeof(mr6));
+        case AF_INET6: {
+            struct ipv6_mreq mr6;
+
+            pa_zero(mr6);
+            mr6.ipv6mr_multiaddr = ((const struct sockaddr_in6*) sa)->sin6_addr;
+            r = setsockopt(fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mr6, sizeof(mr6));
+            break;
+        }
 #endif
+        default:
+            pa_assert_not_reached();
     }
 
     if (r < 0) {
-- 
1.7.8



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux