Changeset 14525


Ignore:
Timestamp:
May 9, 2015, 8:37:55 AM (6 years ago)
Author:
mikedld
Message:

Fix some issues revealed by coverity

Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/conf.c

    r14095 r14525  
    173173  bool boolVal;
    174174
    175   tr_variantDictFindBool (getPrefs (), key, &boolVal);
     175  if (!tr_variantDictFindBool (getPrefs (), key, &boolVal))
     176    boolVal = false;
    176177
    177178  return boolVal != 0;
  • trunk/gtk/tr-prefs.c

    r14241 r14525  
    971971      char buf[128];
    972972      GtkTreeIter iter;
    973       struct tm   tm;
    974       tm.tm_hour = i / 60;
    975       tm.tm_min = i % 60;
    976       tm.tm_sec = 0;
    977       strftime (buf, sizeof (buf), "%H:%M", &tm);
     973      g_snprintf (buf, sizeof (buf), "%02d:%02d", i / 60, i % 60);
    978974      gtk_list_store_append (store, &iter);
    979975      gtk_list_store_set (store, &iter, 0, i, 1, buf, -1);
  • trunk/gtk/util.c

    r14241 r14525  
    432432  GtkCellRenderer * r;
    433433  GtkListStore * store;
    434   va_list vl;
    435434  const char * text;
    436   va_start (vl, text_1);
    437435
    438436  store = gtk_list_store_new (2, G_TYPE_INT, G_TYPE_STRING);
    439437
    440438  text = text_1;
    441   if (text != NULL) do
    442     {
    443       const int val = va_arg (vl, int);
    444       gtk_list_store_insert_with_values (store, NULL, INT_MAX, 0, val, 1, text, -1);
    445       text = va_arg (vl, const char *);
    446     }
    447   while (text != NULL);
     439  if (text != NULL)
     440    {
     441      va_list vl;
     442
     443      va_start (vl, text_1);
     444      do
     445        {
     446          const int val = va_arg (vl, int);
     447          gtk_list_store_insert_with_values (store, NULL, INT_MAX, 0, val, 1, text, -1);
     448          text = va_arg (vl, const char *);
     449        }
     450      while (text != NULL);
     451      va_end (vl);
     452    }
    448453
    449454  w = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
  • trunk/libtransmission/announcer.c

    r14521 r14525  
    11461146            /* if the tracker included scrape fields in its announce response,
    11471147               then a separate scrape isn't needed */
    1148             if ((scrape_fields >= 3) || (!tracker->scrape && (scrape_fields >= 1)))
     1148            if (scrape_fields >= 3 || (scrape_fields >= 1 && tracker->scrape != NULL))
    11491149            {
    11501150                tr_logAddTorDbg (tier->tor, "Announce response contained scrape info; "
  • trunk/libtransmission/peer-mgr.c

    r14483 r14525  
    878878  /* we consider ourselves to be in endgame if the number of bytes
    879879     we've got requested is >= the number of bytes left to download */
    880   return (s->requestCount * s->tor->blockSize)
     880  return ((uint64_t) s->requestCount * s->tor->blockSize)
    881881               >= tr_torrentGetLeftUntilDone (s->tor);
    882882}
     
    19951995      ensureAtomExists (s, addr, port, 0, -1, TR_PEER_FROM_INCOMING);
    19961996      atom = getExistingAtom (s, addr);
     1997
     1998      assert (atom != NULL);
     1999
    19972000      atom->time = tr_time ();
    19982001      atom->piece_data_time = 0;
  • trunk/libtransmission/peer-msgs.c

    r14473 r14525  
    19521952
    19531953        data = tr_torrentGetMetadataPiece (msgs->torrent, piece, &dataLen);
    1954         if ((dataLen > 0) && (data != NULL))
     1954        if (data != NULL)
    19551955        {
    19561956            tr_variant tmp;
  • trunk/libtransmission/rpc-server.c

    r14493 r14525  
    501501                                              webClientDir,
    502502                                              TR_PATH_DELIMITER_STR,
    503                                               subpath && *subpath ? subpath : "index.html");
     503                                              *subpath != '\0' ? subpath : "index.html");
    504504          serve_file (req, server, filename);
    505505          tr_free (filename);
     
    614614          size_t plen;
    615615          char * p = tr_base64_decode_str (auth + 6, &plen);
    616           if (p && plen && ((pass = strchr (p, ':'))))
     616          if (p != NULL)
    617617            {
    618               user = p;
    619               *pass++ = '\0';
     618              if (plen > 0 && (pass = strchr (p, ':')) != NULL)
     619                {
     620                  user = p;
     621                  *pass++ = '\0';
     622                }
     623              else
     624                {
     625                  tr_free (p);
     626                }
    620627            }
    621628        }
  • trunk/libtransmission/torrent-magnet.c

    r14491 r14525  
    193193    }
    194194
     195    assert (ret == NULL || *len > 0);
     196
    195197    return ret;
    196198}
  • trunk/libtransmission/torrent.c

    r14491 r14525  
    20942094torrentCallScript (const tr_torrent * tor, const char * script)
    20952095{
    2096   char timeStr[128];
     2096  char timeStr[128], * newlinePos;
    20972097  const time_t now = tr_time ();
    20982098
    20992099  tr_strlcpy (timeStr, ctime (&now), sizeof (timeStr));
    2100   *strchr (timeStr,'\n') = '\0';
     2100
     2101  /* ctime () includes '\n', but it's better to be safe */
     2102  newlinePos = strchr (timeStr, '\n');
     2103  if (newlinePos != NULL)
     2104    *newlinePos = '\0';
    21012105
    21022106  if (script && *script)
  • trunk/libtransmission/trevent.c

    r14479 r14525  
    285285    assert (tr_isSession (session));
    286286
     287    if (session->events == NULL)
     288        return;
     289
    287290    session->events->die = true;
    288291    tr_logAddDeep (__FILE__, __LINE__, NULL, "closing trevent pipe");
  • trunk/libtransmission/upnp.c

    r14428 r14525  
    283283        errno = 0;
    284284
    285         if (!handle->urls.controlURL || !handle->data.first.servicetype)
     285        if (!handle->urls.controlURL)
    286286            handle->isMapped = 0;
    287287        else
  • trunk/qt/details.cc

    r14509 r14525  
    113113      QTreeWidget * tw (treeWidget ());
    114114      const int column = tw ? tw->sortColumn () : 0;
     115
     116      assert (i != nullptr);
     117
    115118      switch (column)
    116119        {
  • trunk/qt/freespace-label.cc

    r14497 r14525  
    9090  // update the label
    9191  int64_t bytes = -1;
    92   tr_variantDictFindInt (arguments, TR_KEY_size_bytes, &bytes);
    93   if (bytes >= 0)
     92  if (tr_variantDictFindInt (arguments, TR_KEY_size_bytes, &bytes) && bytes >= 0)
    9493    setText (tr("%1 free").arg(Formatter::sizeToString (bytes)));
    9594  else
  • trunk/qt/torrent-filter.cc

    r14499 r14525  
    133133        if (!val)
    134134          val = -compare (a->queuePosition(), b->queuePosition());
     135        // fall through
    135136
    136137      case SortMode::SORT_BY_RATIO:
Note: See TracChangeset for help on using the changeset viewer.