From 0b79b698769a08d8c651859a40f985956dc43622 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Thu, 9 Feb 2017 11:21:38 +0100 Subject: [PATCH] Bug 1338086 - Remove useless else blocks in order to reduce complexity in netwerk/ r=dragana MozReview-Commit-ID: 2TSxhHWmL2H --HG-- extra : rebase_source : a8a70bfc3aec34b85d20021036bd2c13cdcfe5f3 --- netwerk/base/nsURLHelper.cpp | 3 +- netwerk/build/nsNetModule.cpp | 3 +- netwerk/cookie/nsCookieService.cpp | 17 ++- netwerk/dns/DNS.cpp | 38 +++--- netwerk/dns/nsEffectiveTLDService.cpp | 9 +- netwerk/dns/nsHostResolver.cpp | 8 +- .../http/nsHttpChannelAuthProvider.cpp | 4 +- netwerk/sctp/datachannel/DataChannel.cpp | 119 +++++++++--------- 8 files changed, 102 insertions(+), 99 deletions(-) diff --git a/netwerk/base/nsURLHelper.cpp b/netwerk/base/nsURLHelper.cpp index 8def697dac4d..a746bd7d0e66 100644 --- a/netwerk/base/nsURLHelper.cpp +++ b/netwerk/base/nsURLHelper.cpp @@ -1096,7 +1096,8 @@ net_IsValidIPv4Addr(const char *addr, int32_t addrLen) if (octet == 0) { // leading 0 is not allowed return false; - } else if (octet == -1) { + } + if (octet == -1) { octet = *p - '0'; } else { octet *= 10; diff --git a/netwerk/build/nsNetModule.cpp b/netwerk/build/nsNetModule.cpp index bc03b9ab7706..6ddb90de9286 100644 --- a/netwerk/build/nsNetModule.cpp +++ b/netwerk/build/nsNetModule.cpp @@ -348,9 +348,8 @@ WebSocketChannelConstructor(bool aSecure) if (aSecure) { return new WebSocketSSLChannel; - } else { - return new WebSocketChannel; } + return new WebSocketChannel; } #define WEB_SOCKET_HANDLER_CONSTRUCTOR(type, secure) \ diff --git a/netwerk/cookie/nsCookieService.cpp b/netwerk/cookie/nsCookieService.cpp index f1f149ba7d69..0b9718e95174 100644 --- a/netwerk/cookie/nsCookieService.cpp +++ b/netwerk/cookie/nsCookieService.cpp @@ -3585,16 +3585,15 @@ nsCookieService::AddInternal(const nsCookieKey &aKey, BLOCKED_DOWNGRADE_SECURE_INEXACT); } return; + } + // A secure site is allowed to downgrade a secure cookie + // but we want to measure anyway. + if (foundSecureExact) { + Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE, + DOWNGRADE_SECURE_FROM_SECURE_EXACT); } else { - // A secure site is allowed to downgrade a secure cookie - // but we want to measure anyway. - if (foundSecureExact) { - Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE, - DOWNGRADE_SECURE_FROM_SECURE_EXACT); - } else { - Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE, - DOWNGRADE_SECURE_FROM_SECURE_INEXACT); - } + Telemetry::Accumulate(Telemetry::COOKIE_LEAVE_SECURE_ALONE, + DOWNGRADE_SECURE_FROM_SECURE_INEXACT); } } } diff --git a/netwerk/dns/DNS.cpp b/netwerk/dns/DNS.cpp index 643296af002a..12ee1ff73067 100644 --- a/netwerk/dns/DNS.cpp +++ b/netwerk/dns/DNS.cpp @@ -110,7 +110,7 @@ bool NetAddrToString(const NetAddr *addr, char *buf, uint32_t bufSize) nativeAddr.s_addr = addr->inet.ip; return !!inet_ntop_internal(AF_INET, &nativeAddr, buf, bufSize); } - else if (addr->raw.family == AF_INET6) { + if (addr->raw.family == AF_INET6) { if (bufSize < INET6_ADDRSTRLEN) { return false; } @@ -146,11 +146,12 @@ bool IsLoopBackAddress(const NetAddr *addr) if (addr->raw.family == AF_INET) { return (addr->inet.ip == htonl(INADDR_LOOPBACK)); } - else if (addr->raw.family == AF_INET6) { + if (addr->raw.family == AF_INET6) { if (IPv6ADDR_IS_LOOPBACK(&addr->inet6.ip)) { return true; - } else if (IPv6ADDR_IS_V4MAPPED(&addr->inet6.ip) && - IPv6ADDR_V4MAPPED_TO_IPADDR(&addr->inet6.ip) == htonl(INADDR_LOOPBACK)) { + } + if (IPv6ADDR_IS_V4MAPPED(&addr->inet6.ip) && + IPv6ADDR_V4MAPPED_TO_IPADDR(&addr->inet6.ip) == htonl(INADDR_LOOPBACK)) { return true; } } @@ -167,7 +168,8 @@ bool IsIPAddrAny(const NetAddr *addr) else if (addr->raw.family == AF_INET6) { if (IPv6ADDR_IS_UNSPECIFIED(&addr->inet6.ip)) { return true; - } else if (IPv6ADDR_IS_V4MAPPED(&addr->inet6.ip) && + } + if (IPv6ADDR_IS_V4MAPPED(&addr->inet6.ip) && IPv6ADDR_V4MAPPED_TO_IPADDR(&addr->inet6.ip) == htonl(INADDR_ANY)) { return true; } @@ -230,17 +232,20 @@ NetAddr::operator == (const NetAddr& other) const { if (this->raw.family != other.raw.family) { return false; - } else if (this->raw.family == AF_INET) { + } + if (this->raw.family == AF_INET) { return (this->inet.port == other.inet.port) && (this->inet.ip == other.inet.ip); - } else if (this->raw.family == AF_INET6) { + } + if (this->raw.family == AF_INET6) { return (this->inet6.port == other.inet6.port) && (this->inet6.flowinfo == other.inet6.flowinfo) && (memcmp(&this->inet6.ip, &other.inet6.ip, sizeof(this->inet6.ip)) == 0) && (this->inet6.scope_id == other.inet6.scope_id); #if defined(XP_UNIX) - } else if (this->raw.family == AF_LOCAL) { + } + if (this->raw.family == AF_LOCAL) { return PL_strncmp(this->local.path, other.local.path, ArrayLength(this->local.path)); #endif @@ -253,22 +258,23 @@ NetAddr::operator < (const NetAddr& other) const { if (this->raw.family != other.raw.family) { return this->raw.family < other.raw.family; - } else if (this->raw.family == AF_INET) { + } + if (this->raw.family == AF_INET) { if (this->inet.ip == other.inet.ip) { return this->inet.port < other.inet.port; - } else { - return this->inet.ip < other.inet.ip; } - } else if (this->raw.family == AF_INET6) { + return this->inet.ip < other.inet.ip; + } + if (this->raw.family == AF_INET6) { int cmpResult = memcmp(&this->inet6.ip, &other.inet6.ip, sizeof(this->inet6.ip)); if (cmpResult) { return cmpResult < 0; - } else if (this->inet6.port != other.inet6.port) { - return this->inet6.port < other.inet6.port; - } else { - return this->inet6.flowinfo < other.inet6.flowinfo; } + if (this->inet6.port != other.inet6.port) { + return this->inet6.port < other.inet6.port; + } + return this->inet6.flowinfo < other.inet6.flowinfo; } return false; } diff --git a/netwerk/dns/nsEffectiveTLDService.cpp b/netwerk/dns/nsEffectiveTLDService.cpp index 4dab2178fa94..745803b6fae4 100644 --- a/netwerk/dns/nsEffectiveTLDService.cpp +++ b/netwerk/dns/nsEffectiveTLDService.cpp @@ -286,19 +286,18 @@ nsEffectiveTLDService::GetBaseDomainInternal(nsCString &aHostname, // wildcard rules imply an eTLD one level inferior to the match. eTLD = prevDomain; break; - - } else if (entry->IsNormal() || !nextDot) { + } + if (entry->IsNormal() || !nextDot) { // specific match, or we've hit the top domain level eTLD = currDomain; break; - - } else if (entry->IsException()) { + } + if (entry->IsException()) { // exception rules imply an eTLD one level superior to the match. eTLD = nextDot + 1; break; } } - if (!nextDot) { // we've hit the top domain level; use it by default. eTLD = currDomain; diff --git a/netwerk/dns/nsHostResolver.cpp b/netwerk/dns/nsHostResolver.cpp index 8924ed7e4d10..8a5f4bdd0077 100644 --- a/netwerk/dns/nsHostResolver.cpp +++ b/netwerk/dns/nsHostResolver.cpp @@ -6,7 +6,7 @@ #if defined(HAVE_RES_NINIT) #include #include -#include +#include #include #include #define RES_RETRY_ON_FAILURE @@ -294,7 +294,8 @@ nsHostRecord::CheckExpiration(const mozilla::TimeStamp& now) const { if (!mGraceStart.IsNull() && now >= mGraceStart && !mValidEnd.IsNull() && now < mValidEnd) { return nsHostRecord::EXP_GRACE; - } else if (!mValidEnd.IsNull() && now < mValidEnd) { + } + if (!mValidEnd.IsNull() && now < mValidEnd) { return nsHostRecord::EXP_VALID; } @@ -362,7 +363,8 @@ nsHostRecord::GetPriority(uint16_t aFlags) { if (IsHighPriority(aFlags)){ return nsHostRecord::DNS_PRIORITY_HIGH; - } else if (IsMediumPriority(aFlags)) { + } + if (IsMediumPriority(aFlags)) { return nsHostRecord::DNS_PRIORITY_MEDIUM; } diff --git a/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp b/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp index b2635480667a..517704f0dc5d 100644 --- a/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp +++ b/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp @@ -622,7 +622,7 @@ nsHttpChannelAuthProvider::GetCredentials(const char *challenges, break; } - else if (rv == NS_ERROR_IN_PROGRESS) { + if (rv == NS_ERROR_IN_PROGRESS) { // authentication prompt has been invoked and result is // expected asynchronously, save current challenge being // processed and all remaining challenges to use later in @@ -1370,7 +1370,7 @@ NS_IMETHODIMP nsHttpChannelAuthProvider::OnAuthCancelled(nsISupports *aContext, mRemainingChallenges.Truncate(); return ContinueOnAuthAvailable(creds); } - else if (rv == NS_ERROR_IN_PROGRESS) { + if (rv == NS_ERROR_IN_PROGRESS) { // GetCredentials successfully queued another authprompt for // a challenge from the list, we are now waiting for the user // to provide the credentials diff --git a/netwerk/sctp/datachannel/DataChannel.cpp b/netwerk/sctp/datachannel/DataChannel.cpp index 9da4b3c2c48f..1cadd08b861c 100644 --- a/netwerk/sctp/datachannel/DataChannel.cpp +++ b/netwerk/sctp/datachannel/DataChannel.cpp @@ -586,10 +586,9 @@ DataChannelConnection::CompleteConnect(TransportFlow *flow, TransportLayer::Stat if (errno == EINPROGRESS) { // non-blocking return; - } else { - LOG(("usrsctp_connect failed: %d", errno)); - mState = CLOSED; } + LOG(("usrsctp_connect failed: %d", errno)); + mState = CLOSED; } else { // We set Even/Odd and fire ON_CONNECTION via SCTP_COMM_UP when we get that // This also avoids issues with calling TransportFlow stuff on Mainthread @@ -1783,50 +1782,49 @@ DataChannelConnection::HandleStreamChangeEvent(const struct sctp_stream_change_e strchg->strchange_outstrms)); // XXX FIX! notify pending opens of failure return; - } else { - if (strchg->strchange_instrms > mStreams.Length()) { - LOG(("Other side increased streams from %u to %u", - mStreams.Length(), strchg->strchange_instrms)); - } - if (strchg->strchange_outstrms > mStreams.Length() || - strchg->strchange_instrms > mStreams.Length()) { - uint16_t old_len = mStreams.Length(); - uint16_t new_len = std::max(strchg->strchange_outstrms, - strchg->strchange_instrms); - LOG(("Increasing number of streams from %u to %u - adding %u (in: %u)", - old_len, new_len, new_len - old_len, - strchg->strchange_instrms)); - // make sure both are the same length - mStreams.AppendElements(new_len - old_len); - LOG(("New length = %d (was %d)", mStreams.Length(), old_len)); - for (size_t i = old_len; i < mStreams.Length(); ++i) { - mStreams[i] = nullptr; - } - // Re-process any channels waiting for streams. - // Linear search, but we don't increase channels often and - // the array would only get long in case of an app error normally - - // Make sure we request enough streams if there's a big jump in streams - // Could make a more complex API for OpenXxxFinish() and avoid this loop - size_t num_needed = mPending.GetSize(); - LOG(("%d of %d new streams already needed", num_needed, - new_len - old_len)); - num_needed -= (new_len - old_len); // number we added - if (num_needed > 0) { - if (num_needed < 16) - num_needed = 16; - LOG(("Not enough new streams, asking for %d more", num_needed)); - RequestMoreStreams(num_needed); - } else if (strchg->strchange_outstrms < strchg->strchange_instrms) { - LOG(("Requesting %d output streams to match partner", - strchg->strchange_instrms - strchg->strchange_outstrms)); - RequestMoreStreams(strchg->strchange_instrms - strchg->strchange_outstrms); - } - - ProcessQueuedOpens(); - } - // else probably not a change in # of streams } + if (strchg->strchange_instrms > mStreams.Length()) { + LOG(("Other side increased streams from %u to %u", + mStreams.Length(), strchg->strchange_instrms)); + } + if (strchg->strchange_outstrms > mStreams.Length() || + strchg->strchange_instrms > mStreams.Length()) { + uint16_t old_len = mStreams.Length(); + uint16_t new_len = std::max(strchg->strchange_outstrms, + strchg->strchange_instrms); + LOG(("Increasing number of streams from %u to %u - adding %u (in: %u)", + old_len, new_len, new_len - old_len, + strchg->strchange_instrms)); + // make sure both are the same length + mStreams.AppendElements(new_len - old_len); + LOG(("New length = %d (was %d)", mStreams.Length(), old_len)); + for (size_t i = old_len; i < mStreams.Length(); ++i) { + mStreams[i] = nullptr; + } + // Re-process any channels waiting for streams. + // Linear search, but we don't increase channels often and + // the array would only get long in case of an app error normally + + // Make sure we request enough streams if there's a big jump in streams + // Could make a more complex API for OpenXxxFinish() and avoid this loop + size_t num_needed = mPending.GetSize(); + LOG(("%d of %d new streams already needed", num_needed, + new_len - old_len)); + num_needed -= (new_len - old_len); // number we added + if (num_needed > 0) { + if (num_needed < 16) + num_needed = 16; + LOG(("Not enough new streams, asking for %d more", num_needed)); + RequestMoreStreams(num_needed); + } else if (strchg->strchange_outstrms < strchg->strchange_instrms) { + LOG(("Requesting %d output streams to match partner", + strchg->strchange_instrms - strchg->strchange_outstrms)); + RequestMoreStreams(strchg->strchange_instrms - strchg->strchange_outstrms); + } + + ProcessQueuedOpens(); + } + // else probably not a change in # of streams for (uint32_t i = 0; i < mStreams.Length(); ++i) { channel = mStreams[i]; @@ -2117,22 +2115,21 @@ DataChannelConnection::OpenFinish(already_AddRefed&& aChannel) // Note: we're locked, so there's no danger of a race with the // buffer-threshold callback return channel.forget(); - } else { - if (channel->mFlags & DATA_CHANNEL_FLAGS_FINISH_OPEN) { - // We already returned the channel to the app. - NS_ERROR("Failed to send open request"); - NS_DispatchToMainThread(do_AddRef(new DataChannelOnMessageAvailable( - DataChannelOnMessageAvailable::ON_CHANNEL_CLOSED, this, - channel))); - } - // If we haven't returned the channel yet, it will get destroyed when we exit - // this function. - mStreams[stream] = nullptr; - channel->mStream = INVALID_STREAM; - // we'll be destroying the channel - channel->mState = CLOSED; - return nullptr; } + if (channel->mFlags & DATA_CHANNEL_FLAGS_FINISH_OPEN) { + // We already returned the channel to the app. + NS_ERROR("Failed to send open request"); + NS_DispatchToMainThread(do_AddRef(new DataChannelOnMessageAvailable( + DataChannelOnMessageAvailable::ON_CHANNEL_CLOSED, this, + channel))); + } + // If we haven't returned the channel yet, it will get destroyed when we exit + // this function. + mStreams[stream] = nullptr; + channel->mStream = INVALID_STREAM; + // we'll be destroying the channel + channel->mState = CLOSED; + return nullptr; /* NOTREACHED */ } }