]> granicus.if.org Git - transmission/commitdiff
Fix some issues revealed by coverity
authorMike Gelfand <mikedld@mikedld.com>
Sat, 9 May 2015 08:37:55 +0000 (08:37 +0000)
committerMike Gelfand <mikedld@mikedld.com>
Sat, 9 May 2015 08:37:55 +0000 (08:37 +0000)
14 files changed:
gtk/conf.c
gtk/tr-prefs.c
gtk/util.c
libtransmission/announcer.c
libtransmission/peer-mgr.c
libtransmission/peer-msgs.c
libtransmission/rpc-server.c
libtransmission/torrent-magnet.c
libtransmission/torrent.c
libtransmission/trevent.c
libtransmission/upnp.c
qt/details.cc
qt/freespace-label.cc
qt/torrent-filter.cc

index 6302d4738c9c9b19a578e71de353d64307439246..6803fb15a68fea162b5884425ed750125837e4bc 100644 (file)
@@ -172,7 +172,8 @@ gtr_pref_flag_get (const tr_quark key)
 {
   bool boolVal;
 
-  tr_variantDictFindBool (getPrefs (), key, &boolVal);
+  if (!tr_variantDictFindBool (getPrefs (), key, &boolVal))
+    boolVal = false;
 
   return boolVal != 0;
 }
index 1298c5745d598ebe53c6c332a08bfcb3c8b4dac1..0e14a87ab9eb4b820bce2cc387ee2b353da887f3 100644 (file)
@@ -970,11 +970,7 @@ new_time_combo (GObject * core, const tr_quark key)
     {
       char buf[128];
       GtkTreeIter iter;
-      struct tm   tm;
-      tm.tm_hour = i / 60;
-      tm.tm_min = i % 60;
-      tm.tm_sec = 0;
-      strftime (buf, sizeof (buf), "%H:%M", &tm);
+      g_snprintf (buf, sizeof (buf), "%02d:%02d", i / 60, i % 60);
       gtk_list_store_append (store, &iter);
       gtk_list_store_set (store, &iter, 0, i, 1, buf, -1);
     }
index 838393e2c0cfa52e8251866d43d15207912c87ba..6f96ec583843a7012c217f63a23e3c4461c78808 100644 (file)
@@ -431,20 +431,25 @@ gtr_combo_box_new_enum (const char * text_1, ...)
   GtkWidget * w;
   GtkCellRenderer * r;
   GtkListStore * store;
-  va_list vl;
   const char * text;
-  va_start (vl, text_1);
 
   store = gtk_list_store_new (2, G_TYPE_INT, G_TYPE_STRING);
 
   text = text_1;
-  if (text != NULL) do
+  if (text != NULL)
     {
-      const int val = va_arg (vl, int);
-      gtk_list_store_insert_with_values (store, NULL, INT_MAX, 0, val, 1, text, -1);
-      text = va_arg (vl, const char *);
+      va_list vl;
+
+      va_start (vl, text_1);
+      do
+        {
+          const int val = va_arg (vl, int);
+          gtk_list_store_insert_with_values (store, NULL, INT_MAX, 0, val, 1, text, -1);
+          text = va_arg (vl, const char *);
+        }
+      while (text != NULL);
+      va_end (vl);
     }
-  while (text != NULL);
 
   w = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
   r = gtk_cell_renderer_text_new ();
index 00cbc814078ea01135bd94beb185525ad9d6d7a7..f5b79a753e3c40b8cef11c7266d2f70433018cf5 100644 (file)
@@ -1145,7 +1145,7 @@ on_announce_done (const tr_announce_response  * response,
 
             /* if the tracker included scrape fields in its announce response,
                then a separate scrape isn't needed */
-            if ((scrape_fields >= 3) || (!tracker->scrape && (scrape_fields >= 1)))
+            if (scrape_fields >= 3 || (scrape_fields >= 1 && tracker->scrape != NULL))
             {
                 tr_logAddTorDbg (tier->tor, "Announce response contained scrape info; "
                                       "rescheduling next scrape to %d seconds from now.",
index c490facc2fde64570cc71d1eebc0f8050f386837..642de1274a7b4d84bd8c3a665a3bbe2a57fe83a9 100644 (file)
@@ -877,7 +877,7 @@ testForEndgame (const tr_swarm * s)
 {
   /* we consider ourselves to be in endgame if the number of bytes
      we've got requested is >= the number of bytes left to download */
-  return (s->requestCount * s->tor->blockSize)
+  return ((uint64_t) s->requestCount * s->tor->blockSize)
                >= tr_torrentGetLeftUntilDone (s->tor);
 }
 
@@ -1994,6 +1994,9 @@ myHandshakeDoneCB (tr_handshake  * handshake,
 
       ensureAtomExists (s, addr, port, 0, -1, TR_PEER_FROM_INCOMING);
       atom = getExistingAtom (s, addr);
+
+      assert (atom != NULL);
+
       atom->time = tr_time ();
       atom->piece_data_time = 0;
       atom->lastConnectionAt = tr_time ();
index 17dcd3896b3c1254afbecb2ef1a448b54a963ccc..36fe7313b8705895f96c7b83d25ba3219fd9689d 100644 (file)
@@ -1951,7 +1951,7 @@ fillOutputBuffer (tr_peerMsgs * msgs, time_t now)
         bool ok = false;
 
         data = tr_torrentGetMetadataPiece (msgs->torrent, piece, &dataLen);
-        if ((dataLen > 0) && (data != NULL))
+        if (data != NULL)
         {
             tr_variant tmp;
             struct evbuffer * payload;
index 634e633b8311fe13bfeaf0a2bd83c163199abdb7..6064d820b8dfc6907b4b27a0a28f2f5978b23b6f 100644 (file)
@@ -500,7 +500,7 @@ handle_web_client (struct evhttp_request * req,
           char * filename = tr_strdup_printf ("%s%s%s",
                                               webClientDir,
                                               TR_PATH_DELIMITER_STR,
-                                              subpath && *subpath ? subpath : "index.html");
+                                              *subpath != '\0' ? subpath : "index.html");
           serve_file (req, server, filename);
           tr_free (filename);
         }
@@ -613,10 +613,17 @@ handle_request (struct evhttp_request * req, void * arg)
         {
           size_t plen;
           char * p = tr_base64_decode_str (auth + 6, &plen);
-          if (p && plen && ((pass = strchr (p, ':'))))
+          if (p != NULL)
             {
-              user = p;
-              *pass++ = '\0';
+              if (plen > 0 && (pass = strchr (p, ':')) != NULL)
+                {
+                  user = p;
+                  *pass++ = '\0';
+                }
+              else
+                {
+                  tr_free (p);
+                }
             }
         }
 
index fd71cd75c304dc797873c576261b7351d5c7c5a6..8b40bc1d25ed90cf3fb5ef8c9da79bfd0a5a68df 100644 (file)
@@ -192,6 +192,8 @@ tr_torrentGetMetadataPiece (tr_torrent * tor, int piece, int * len)
         }
     }
 
+    assert (ret == NULL || *len > 0);
+
     return ret;
 }
 
index 03ff37b2c6b0eb602c69b2acb294b3258fe89ae0..8c33b99eacec1a1e4d2971822b6bb41e80a0aa97 100644 (file)
@@ -2093,11 +2093,15 @@ onSigCHLD (int i UNUSED)
 static void
 torrentCallScript (const tr_torrent * tor, const char * script)
 {
-  char timeStr[128];
+  char timeStr[128], * newlinePos;
   const time_t now = tr_time ();
 
   tr_strlcpy (timeStr, ctime (&now), sizeof (timeStr));
-  *strchr (timeStr,'\n') = '\0';
+
+  /* ctime () includes '\n', but it's better to be safe */
+  newlinePos = strchr (timeStr, '\n');
+  if (newlinePos != NULL)
+    *newlinePos = '\0';
 
   if (script && *script)
     {
index e70218834f76dbeaaaf167cb710aaecfef641bfa..7c2ae089cd63ac4498b24816583bf78d50074654 100644 (file)
@@ -284,6 +284,9 @@ tr_eventClose (tr_session * session)
 {
     assert (tr_isSession (session));
 
+    if (session->events == NULL)
+        return;
+
     session->events->die = true;
     tr_logAddDeep (__FILE__, __LINE__, NULL, "closing trevent pipe");
     tr_netCloseSocket (session->events->fds[1]);
index 35b0d153f50073a91dd9106c0e22245d948b4148..59d4ed77324cca93ac4516822581dc681069e962 100644 (file)
@@ -282,7 +282,7 @@ tr_upnpPulse (tr_upnp * handle,
         int  err_udp = -1;
         errno = 0;
 
-        if (!handle->urls.controlURL || !handle->data.first.servicetype)
+        if (!handle->urls.controlURL)
             handle->isMapped = 0;
         else
         {
index ba5217d3bb3071e1c70e4fd17b75ff76f9645b0d..25daa3471924cff3d82148189f6daeeabe5ef503 100644 (file)
@@ -112,6 +112,9 @@ class PeerItem: public QTreeWidgetItem
       const PeerItem * i = dynamic_cast<const PeerItem*> (&other);
       QTreeWidget * tw (treeWidget ());
       const int column = tw ? tw->sortColumn () : 0;
+
+      assert (i != nullptr);
+
       switch (column)
         {
           case COL_UP: return peer.rateToPeer < i->peer.rateToPeer;
index 16ce02f15661986b104e8251385954752ffb8dca..aa76b021248760286ab9287896635ea020693041 100644 (file)
@@ -89,8 +89,7 @@ FreespaceLabel::onSessionExecuted (int64_t tag, const QString& result, tr_varian
 
   // update the label
   int64_t bytes = -1;
-  tr_variantDictFindInt (arguments, TR_KEY_size_bytes, &bytes);
-  if (bytes >= 0)
+  if (tr_variantDictFindInt (arguments, TR_KEY_size_bytes, &bytes) && bytes >= 0)
     setText (tr("%1 free").arg(Formatter::sizeToString (bytes)));
   else
     setText (QString ());
index 6d50fc74d3182a79348e1d51ea730e790b5f5ee3..53c56855420543ad79a074b1d26a0560cafb7a6b 100644 (file)
@@ -132,6 +132,7 @@ TorrentFilter::lessThan (const QModelIndex& left, const QModelIndex& right) cons
           val = a->compareSeedRatio (*b);
         if (!val)
           val = -compare (a->queuePosition(), b->queuePosition());
+        // fall through
 
       case SortMode::SORT_BY_RATIO:
         if (!val)