From: Mike Gelfand Date: Sat, 20 May 2017 20:31:56 +0000 (+0300) Subject: Fix some issues reported by Coverity X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=82722476aa7db3806884b90400755e96bd0b32a1;p=transmission Fix some issues reported by Coverity --- diff --git a/libtransmission/fdlimit.c b/libtransmission/fdlimit.c index 77d56fff7..fc656e591 100644 --- a/libtransmission/fdlimit.c +++ b/libtransmission/fdlimit.c @@ -568,13 +568,23 @@ tr_socket_t tr_fdSocketCreate(tr_session* session, int domain, int type) if (!buf_logged) { - int i; - socklen_t size = sizeof(int); + int i = 0; + socklen_t size = sizeof(i); + + if (getsockopt(s, SOL_SOCKET, SO_SNDBUF, (void*)&i, &size) != -1) + { + tr_logAddDebug("SO_SNDBUF size is %d", i); + } + + i = 0; + size = sizeof(i); + + if (getsockopt(s, SOL_SOCKET, SO_RCVBUF, (void*)&i, &size) != -1) + { + tr_logAddDebug("SO_RCVBUF size is %d", i); + } + buf_logged = true; - getsockopt(s, SOL_SOCKET, SO_SNDBUF, (void*)&i, &size); - tr_logAddDebug("SO_SNDBUF size is %d", i); - getsockopt(s, SOL_SOCKET, SO_RCVBUF, (void*)&i, &size); - tr_logAddDebug("SO_RCVBUF size is %d", i); } } diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index 44926fe06..73eadb0ef 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -1546,6 +1546,9 @@ static void refillUpkeep(evutil_socket_t foo UNUSED, short bar UNUSED, void* vmg if (msgs != NULL && request->sentAt <= too_old && !tr_peerMsgsIsReadingBlock(msgs, request->block)) { + assert(cancel != NULL); + assert(cancelCount < cancel_buflen); + cancel[cancelCount++] = *request; } else diff --git a/libtransmission/quark.c b/libtransmission/quark.c index dbff574f6..90e35d06f 100644 --- a/libtransmission/quark.c +++ b/libtransmission/quark.c @@ -479,9 +479,10 @@ tr_quark tr_quark_new(void const* str, size_t len) if (str == NULL) { - len = 0; + goto finish; } - else if (len == TR_BAD_SIZE) + + if (len == TR_BAD_SIZE) { len = strlen(str); } @@ -491,6 +492,7 @@ tr_quark tr_quark_new(void const* str, size_t len) ret = append_new_quark(str, len); } +finish: return ret; } diff --git a/libtransmission/session.h b/libtransmission/session.h index f73d3af30..df548a8be 100644 --- a/libtransmission/session.h +++ b/libtransmission/session.h @@ -300,7 +300,7 @@ static inline double toSpeedKBps(unsigned int Bps) static inline uint64_t toMemBytes(unsigned int MB) { - uint64_t B = tr_mem_K * tr_mem_K; + uint64_t B = (uint64_t)tr_mem_K * tr_mem_K; B *= MB; return B; } diff --git a/qt/TorrentFilter.cc b/qt/TorrentFilter.cc index 5238ac7f2..5a5a4b11e 100644 --- a/qt/TorrentFilter.cc +++ b/qt/TorrentFilter.cc @@ -48,6 +48,8 @@ void TorrentFilter::refreshPref(int key) /* force a re-sort */ sort(0, !myPrefs.getBool(Prefs::SORT_REVERSED) ? Qt::AscendingOrder : Qt::DescendingOrder); + // fall through + case Prefs::SORT_MODE: case Prefs::SORT_REVERSED: sort(0, myPrefs.getBool(Prefs::SORT_REVERSED) ? Qt::AscendingOrder : Qt::DescendingOrder);