Changeset 14526


Ignore:
Timestamp:
May 9, 2015, 11:56:35 AM (6 years ago)
Author:
mikedld
Message:

Fix some issues revealed by coverity

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/conf.c

    r14525 r14526  
    135135gtr_pref_int_get (const tr_quark key)
    136136{
    137   int64_t i = 0;
    138 
    139   tr_variantDictFindInt (getPrefs (), key, &i);
    140 
    141   return i;
     137  int64_t i;
     138
     139  return tr_variantDictFindInt (getPrefs (), key, &i) ? i : 0;
    142140}
    143141
     
    151149gtr_pref_double_get (const tr_quark key)
    152150{
    153   double d = 0.0;
    154 
    155   tr_variantDictFindReal (getPrefs (), key, &d);
    156 
    157   return d;
     151  double d;
     152
     153  return tr_variantDictFindReal (getPrefs (), key, &d) ? d : 0.0;
    158154}
    159155
     
    173169  bool boolVal;
    174170
    175   if (!tr_variantDictFindBool (getPrefs (), key, &boolVal))
    176     boolVal = false;
    177 
    178   return boolVal != 0;
     171  return tr_variantDictFindBool (getPrefs (), key, &boolVal) ? boolVal : false;
    179172}
    180173
     
    192185gtr_pref_string_get (const tr_quark key)
    193186{
    194   const char * str = NULL;
    195 
    196   tr_variantDictFindStr (getPrefs (), key, &str, NULL);
    197 
    198   return str;
     187  const char * str;
     188
     189  return tr_variantDictFindStr (getPrefs (), key, &str, NULL) ? str : NULL;
    199190}
    200191
  • trunk/gtk/filter.c

    r14241 r14526  
    183183
    184184  /* update the "all" count */
    185   gtk_tree_model_iter_children (model, &iter, NULL);
    186   tracker_model_update_count (store, &iter, all);
     185  if (gtk_tree_model_iter_children (model, &iter, NULL))
     186    tracker_model_update_count (store, &iter, all);
    187187
    188188  store_pos = first_tracker_pos;
  • trunk/gtk/tr-core.c

    r14133 r14526  
    18021802{
    18031803  tr_variant * args;
    1804   bool is_open = FALSE;
    1805 
    1806   if (tr_variantDictFindDict (response, TR_KEY_arguments, &args))
    1807     tr_variantDictFindBool (args, TR_KEY_port_is_open, &is_open);
     1804  bool is_open;
     1805
     1806  if (!tr_variantDictFindDict (response, TR_KEY_arguments, &args) ||
     1807      !tr_variantDictFindBool (args, TR_KEY_port_is_open, &is_open))
     1808    is_open = false;
    18081809
    18091810  core_emit_port_tested (core, is_open);
     
    18271828{
    18281829  tr_variant * args;
    1829   int64_t ruleCount = -1;
    1830 
    1831   if (tr_variantDictFindDict (response, TR_KEY_arguments, &args))
    1832     tr_variantDictFindInt (args, TR_KEY_blocklist_size, &ruleCount);
     1830  int64_t ruleCount;
     1831
     1832  if (!tr_variantDictFindDict (response, TR_KEY_arguments, &args) ||
     1833      !tr_variantDictFindInt (args, TR_KEY_blocklist_size, &ruleCount))
     1834    ruleCount = -1;
    18331835
    18341836  if (ruleCount > 0)
  • trunk/gtk/util.c

    r14525 r14526  
    348348  if (!uri)
    349349    {
    350       int major, minor;
    351350      const char * fmt = "http://www.transmissionbt.com/help/gtk/%d.%dx";
    352       sscanf (SHORT_VERSION_STRING, "%d.%d", &major, &minor);
    353       uri = g_strdup_printf (fmt, major, minor / 10);
     351      uri = g_strdup_printf (fmt, MAJOR_VERSION, MINOR_VERSION / 10);
    354352    }
    355353
  • trunk/libtransmission/bitfield.c

    r14435 r14526  
    160160tr_bitfieldCountTrueBits (const tr_bitfield * b)
    161161{
    162   tr_bitfieldIsValid (b);
     162  assert (tr_bitfieldIsValid (b));
    163163
    164164  return b->true_count;
  • trunk/libtransmission/peer-io.c

    r14479 r14526  
    398398{
    399399    if (algorithm && *algorithm)
    400     {
    401         const int rc = tr_netSetCongestionControl (socket, algorithm);
    402 
    403         if (rc < 0)
    404             tr_logAddNamedInfo ("Net", "Can't set congestion control algorithm '%s': %s",
    405                      algorithm, tr_strerror (errno));
    406     }
     400        tr_netSetCongestionControl (socket, algorithm);
    407401}
    408402
  • trunk/libtransmission/rpcimpl.c

    r14517 r14526  
    355355  int torrentCount;
    356356  tr_rpc_callback_type type;
    357   bool deleteFlag = false;
     357  bool deleteFlag;
    358358  tr_torrent ** torrents;
    359359
    360360  assert (idle_data == NULL);
    361361
    362   tr_variantDictFindBool (args_in, TR_KEY_delete_local_data, &deleteFlag);
     362  if (!tr_variantDictFindBool (args_in, TR_KEY_delete_local_data, &deleteFlag))
     363    deleteFlag = false;
    363364  type = deleteFlag ? TR_RPC_TORRENT_TRASHING
    364365                    : TR_RPC_TORRENT_REMOVING;
     
    13511352  else
    13521353    {
    1353       bool move = false;
     1354      bool move;
    13541355      int i, torrentCount;
    13551356      tr_torrent ** torrents = getTorrents (session, args_in, &torrentCount);
    13561357
    1357       tr_variantDictFindBool (args_in, TR_KEY_move, &move);
     1358      if (!tr_variantDictFindBool (args_in, TR_KEY_move, &move))
     1359        move = false;
    13581360
    13591361      for (i=0; i<torrentCount; ++i)
  • trunk/libtransmission/session.c

    r14524 r14526  
    460460{
    461461  char * filename;
     462  tr_variant oldDict;
    462463  tr_variant fileSettings;
    463   tr_variant sessionDefaults;
    464   tr_variant tmp;
    465464  bool success;
    466465  tr_error * error = NULL;
     
    470469  /* initializing the defaults: caller may have passed in some app-level defaults.
    471470   * preserve those and use the session defaults to fill in any missing gaps. */
    472   tr_variantInitDict (&sessionDefaults, 0);
    473   tr_sessionGetDefaultSettings (&sessionDefaults);
    474   tr_variantMergeDicts (&sessionDefaults, dict);
    475   tmp = *dict;
    476   *dict = sessionDefaults;
    477   sessionDefaults = tmp;
     471  oldDict = *dict;
     472  tr_variantInitDict (dict, 0);
     473  tr_sessionGetDefaultSettings (dict);
     474  tr_variantMergeDicts (dict, &oldDict);
     475  tr_variantFree (&oldDict);
    478476
    479477  /* if caller didn't specify a config dir, use the default */
     
    496494
    497495  /* cleanup */
    498   tr_variantFree (&sessionDefaults);
    499496  tr_free (filename);
    500497  return success;
  • trunk/libtransmission/tr-lpd.c

    r14479 r14526  
    642642        struct sockaddr_in foreignAddr;
    643643        int addrLen = sizeof foreignAddr;
    644 
    645         /* be paranoid enough about zero terminating the foreign string */
    646         char foreignMsg[lpd_maxDatagramLength + 1] = { 0 };
     644        char foreignMsg[lpd_maxDatagramLength + 1];
    647645
    648646        /* process local announcement from foreign peer */
     
    662660                };
    663661
     662            /* be paranoid enough about zero terminating the foreign string */
     663            foreignMsg[res] = '\0';
     664
    664665            foreignPeer.addr.addr.addr4 = foreignAddr.sin_addr;
    665666            if (tr_lpdConsiderAnnounce (&foreignPeer, foreignMsg) != 0)
  • trunk/qt/session.cc

    r14499 r14526  
    683683      case TAG_PORT_TEST:
    684684        {
    685           bool isOpen = false;
    686           if (args != nullptr)
    687             tr_variantDictFindBool (args, TR_KEY_port_is_open, &isOpen);
     685          bool isOpen;
     686          if (args == nullptr ||
     687              !tr_variantDictFindBool (args, TR_KEY_port_is_open, &isOpen))
     688            isOpen = false;
    688689          emit portTested (isOpen);
    689690          break;
Note: See TracChangeset for help on using the changeset viewer.