From bf77d08882bab00549642aeac903560fd76a4a98 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= <olivier.crete@collabora.com>
Date: Thu, 27 Dec 2018 16:25:28 -0600
Subject: [PATCH] Fix little bugs found by clang-analyzer

---
 agent/agent.c            | 2 ++
 agent/conncheck.c        | 4 ++--
 stun/tests/test-format.c | 2 +-
 stun/usages/bind.c       | 2 ++
 tests/test-gstreamer.c   | 5 -----
 5 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/agent/agent.c b/agent/agent.c
index d7ba019..3c1cdcd 100644
--- a/agent/agent.c
+++ b/agent/agent.c
@@ -5849,6 +5849,8 @@ nice_agent_set_software (NiceAgent *agent, const gchar *software)
   if (software)
     agent->software_attribute = g_strdup_printf ("%s/%s",
         software, PACKAGE_STRING);
+  else
+    agent->software_attribute = NULL;
 
   nice_agent_reset_all_stun_agents (agent, TRUE);
 
diff --git a/agent/conncheck.c b/agent/conncheck.c
index 2974415..66290b3 100644
--- a/agent/conncheck.c
+++ b/agent/conncheck.c
@@ -3852,7 +3852,7 @@ static bool conncheck_stun_validater (StunAgent *agent,
     ufrag = NULL;
     if (cand->username)
       ufrag = cand->username;
-    else if (data->stream)
+    else
       ufrag = data->stream->local_ufrag;
     ufrag_len = ufrag? strlen (ufrag) : 0;
 
@@ -3873,7 +3873,7 @@ static bool conncheck_stun_validater (StunAgent *agent,
 
       if (cand->password)
         pass = cand->password;
-      else if(data->stream->local_password[0])
+      else if (data->stream && data->stream->local_password[0])
         pass = data->stream->local_password;
 
       if (pass) {
diff --git a/stun/tests/test-format.c b/stun/tests/test-format.c
index 735b073..0fd70e6 100644
--- a/stun/tests/test-format.c
+++ b/stun/tests/test-format.c
@@ -251,7 +251,7 @@ int main (void)
   if (stun_message_append_xor_addr (&msg, 0xffff, &addr.storage,
           sizeof (addr)) != STUN_MESSAGE_RETURN_NOT_ENOUGH_SPACE)
     fatal ("Address overflow test failed");
-  len = sizeof (msg);
+
   if (stun_agent_finish_message (&agent, &msg, NULL, 0) != 0)
     fatal ("Fingerprint overflow test failed");
   if (stun_agent_finish_message (&agent, &msg, pwd, strlen ((char *) pwd)) != 0)
diff --git a/stun/usages/bind.c b/stun/usages/bind.c
index ee600a0..504bd89 100644
--- a/stun/usages/bind.c
+++ b/stun/usages/bind.c
@@ -483,6 +483,8 @@ StunUsageBindReturn stun_usage_bind_run (const struct sockaddr *srv,
   socklen_t alternate_server_len = sizeof (alternate_server);
   StunUsageBindReturn bind_ret;
 
+  trans.fd = -1;
+
   stun_agent_init (&agent, STUN_ALL_KNOWN_ATTRIBUTES,
       STUN_COMPATIBILITY_RFC3489, 0);
 
diff --git a/tests/test-gstreamer.c b/tests/test-gstreamer.c
index f060efc..2981c00 100644
--- a/tests/test-gstreamer.c
+++ b/tests/test-gstreamer.c
@@ -105,7 +105,6 @@ create_buffer_list (void)
   GstBufferList *list;
   GstBuffer *rtp_buffer;
   GstBuffer *data_buffer;
-  gint total_size = 0;
 
   list = gst_buffer_list_new ();
 
@@ -122,8 +121,6 @@ create_buffer_list (void)
   /* Create a new group to hold the rtp header and the payload */
   gst_buffer_list_add (list, gst_buffer_append (rtp_buffer, data_buffer));
 
-  total_size += gst_buffer_get_size (rtp_buffer);
-
   /***  Second group, i.e. second packet. ***/
 
   /* Create the RTP header buffer */
@@ -137,8 +134,6 @@ create_buffer_list (void)
   /* Create a new group to hold the rtp header and the payload */
   gst_buffer_list_add (list, gst_buffer_append (rtp_buffer, data_buffer));
 
-  total_size += gst_buffer_get_size (rtp_buffer);
-
   /* Calculate the size of the data */
   data_size = 2 * RTP_HEADER_SIZE + 2 * RTP_PAYLOAD_SIZE;
 
-- 
2.27.0

