Bug 1311669 - Replace integer literals which are cast to bool. draft
authorAndi-Bogdan Postelnicu <bpostelnicu@mozilla.com>
Tue, 01 Nov 2016 14:44:10 +0200
changeset 432195 3230538f0747227a74790d1c740774058860258b
parent 432194 7fc20660d51d58cdc6582667f8e0ee3ea990096e
child 432197 a37c7788de51ecde620ede66a445d8f6ab90e4cb
push id34230
push userbmo:bpostelnicu@mozilla.com
push dateTue, 01 Nov 2016 12:45:01 +0000
bugs1311669
milestone52.0a1
Bug 1311669 - Replace integer literals which are cast to bool. MozReview-Commit-ID: LdvpF0mFA5V
netwerk/cookie/nsCookieService.cpp
netwerk/dns/nsEffectiveTLDService.cpp
netwerk/protocol/http/AlternateServices.cpp
netwerk/sctp/datachannel/DataChannel.cpp
netwerk/test/PropertiesTest.cpp
--- a/netwerk/cookie/nsCookieService.cpp
+++ b/netwerk/cookie/nsCookieService.cpp
@@ -473,17 +473,17 @@ public:
   }
 
   void Cancel() { mCanceled = true; }
 
   NS_IMETHOD HandleResult(mozIStorageResultSet *aResult) override
   {
     nsCOMPtr<mozIStorageRow> row;
 
-    while (1) {
+    while (true) {
       DebugOnly<nsresult> rv = aResult->GetNextRow(getter_AddRefs(row));
       NS_ASSERT_SUCCESS(rv);
 
       if (!row)
         break;
 
       CookieDomainTuple *tuple = mDBState->hostArray.AppendElement();
       row->GetUTF8String(IDX_BASE_DOMAIN, tuple->key.mBaseDomain);
@@ -1018,17 +1018,17 @@ nsCookieService::TryInitDB(bool aRecreat
         nsCOMPtr<mozIStorageStatement> update;
         rv = mDefaultDBState->dbConn->CreateStatement(NS_LITERAL_CSTRING(
           "UPDATE moz_cookies SET baseDomain = :baseDomain WHERE id = :id"),
           getter_AddRefs(update));
         NS_ENSURE_SUCCESS(rv, RESULT_RETRY);
 
         nsCString baseDomain, host;
         bool hasResult;
-        while (1) {
+        while (true) {
           rv = select->ExecuteStep(&hasResult);
           NS_ENSURE_SUCCESS(rv, RESULT_RETRY);
 
           if (!hasResult)
             break;
 
           int64_t id = select->AsInt64(SCHEMA2_IDX_ID);
           select->GetUTF8String(SCHEMA2_IDX_HOST, host);
@@ -1095,17 +1095,17 @@ nsCookieService::TryInitDB(bool aRecreat
         if (hasResult) {
           nsCString name1, host1, path1;
           int64_t id1 = select->AsInt64(SCHEMA3_IDX_ID);
           select->GetUTF8String(SCHEMA3_IDX_NAME, name1);
           select->GetUTF8String(SCHEMA3_IDX_HOST, host1);
           select->GetUTF8String(SCHEMA3_IDX_PATH, path1);
 
           nsCString name2, host2, path2;
-          while (1) {
+          while (true) {
             // Read the second row.
             rv = select->ExecuteStep(&hasResult);
             NS_ENSURE_SUCCESS(rv, RESULT_RETRY);
 
             if (!hasResult)
               break;
 
             int64_t id2 = select->AsInt64(SCHEMA3_IDX_ID);
@@ -2128,17 +2128,17 @@ nsCookieService::NotifyThirdParty(nsIURI
     rv = channelURI->GetHost(referringHost);
     if (NS_FAILED(rv)) {
       break;
     }
 
     nsAutoString referringHostUTF16 = NS_ConvertUTF8toUTF16(referringHost);
     os->NotifyObservers(aHostURI, topic, referringHostUTF16.get());
     return;
-  } while (0);
+  } while (false);
 
   // This can fail for a number of reasons, in which kind we fallback to "?"
   os->NotifyObservers(aHostURI, topic, u"?");
 }
 
 // notify observers that the cookie list changed. there are five possible
 // values for aData:
 // "deleted" means a cookie was deleted. aSubject is the deleted cookie.
@@ -2717,17 +2717,17 @@ nsCookieService::EnsureReadDomain(const 
   aKey.mOriginAttributes.CreateSuffix(suffix);
   rv = mDefaultDBState->stmtReadDomain->BindUTF8StringByName(
     NS_LITERAL_CSTRING("originAttributes"), suffix);
   NS_ASSERT_SUCCESS(rv);
 
   bool hasResult;
   nsCString name, value, host, path;
   AutoTArray<RefPtr<nsCookie>, kMaxCookiesPerHost> array;
-  while (1) {
+  while (true) {
     rv = mDefaultDBState->stmtReadDomain->ExecuteStep(&hasResult);
     if (NS_FAILED(rv)) {
       // Recreate the database.
       COOKIE_LOGSTRING(LogLevel::Debug,
         ("EnsureReadDomain(): corruption detected when reading result "
          "with rv 0x%x", rv));
       HandleCorruptDB(mDefaultDBState);
       return;
@@ -2794,17 +2794,17 @@ nsCookieService::EnsureReadComplete()
        "with rv 0x%x", rv));
     HandleCorruptDB(mDefaultDBState);
     return;
   }
 
   nsCString baseDomain, name, value, host, path;
   bool hasResult;
   nsTArray<CookieDomainTuple> array(kMaxNumberOfCookies);
-  while (1) {
+  while (true) {
     rv = stmt->ExecuteStep(&hasResult);
     if (NS_FAILED(rv)) {
       // Recreate the database.
       COOKIE_LOGSTRING(LogLevel::Debug,
         ("EnsureReadComplete(): corruption detected when reading result "
          "with rv 0x%x", rv));
       HandleCorruptDB(mDefaultDBState);
       return;
--- a/netwerk/dns/nsEffectiveTLDService.cpp
+++ b/netwerk/dns/nsEffectiveTLDService.cpp
@@ -267,17 +267,17 @@ nsEffectiveTLDService::GetBaseDomainInte
   // looking for matches at each level.  Note that a given level may
   // have multiple attributes (e.g. IsWild() and IsNormal()).
   const char *prevDomain = nullptr;
   const char *currDomain = aHostname.get();
   const char *nextDot = strchr(currDomain, '.');
   const char *end = currDomain + aHostname.Length();
   // Default value of *eTLD is currDomain as set in the while loop below
   const char *eTLD = nullptr;
-  while (1) {
+  while (true) {
     // sanity check the string we're about to look up: it should not begin with
     // a '.'; this would mean the hostname began with a '.' or had an
     // embedded '..' sequence.
     if (*currDomain == '.')
       return NS_ERROR_INVALID_ARG;
 
     // Perform the lookup.
     const ETLDEntry* entry = ETLDEntry::GetEntry(currDomain);
@@ -323,17 +323,17 @@ nsEffectiveTLDService::GetBaseDomainInte
     if (iter != eTLD) {
       aAdditionalParts = 0;
     }
   } else {
     // count off the number of requested domains.
     begin = aHostname.get();
     iter = eTLD;
 
-    while (1) {
+    while (true) {
       if (iter == begin)
         break;
 
       if (*(--iter) == '.' && aAdditionalParts-- == 0) {
         ++iter;
         ++aAdditionalParts;
         break;
       }
--- a/netwerk/protocol/http/AlternateServices.cpp
+++ b/netwerk/protocol/http/AlternateServices.cpp
@@ -393,17 +393,17 @@ COMPILER ERROR
     _NS_NEXT_TOKEN;
     mStorageEpoch = nsCString(Substring(str, start, idx - start)).ToInteger(&code);
     _NS_NEXT_TOKEN;
     mMixedScheme = Substring(str, start, idx - start).Equals(NS_LITERAL_CSTRING("y"));
     #undef _NS_NEXT_TOKEN
 
     MakeHashKey(mHashKey, mHttps ? NS_LITERAL_CSTRING("https") : NS_LITERAL_CSTRING("http"),
                 mOriginHost, mOriginPort, mPrivate);
-  } while (0);
+  } while (false);
 }
 
 // This is the asynchronous null transaction used to validate
 // an alt-svc advertisement only for https://
 class AltSvcTransaction final : public NullHttpTransaction
 {
 public:
     AltSvcTransaction(AltSvcMapping *map,
--- a/netwerk/sctp/datachannel/DataChannel.cpp
+++ b/netwerk/sctp/datachannel/DataChannel.cpp
@@ -673,17 +673,17 @@ DataChannelConnection::SctpDtlsOutput(vo
       usrsctp_freedumpbuffer(buf);
     }
   }
   // We're async proxying even if on the STSThread because this is called
   // with internal SCTP locks held in some cases (such as in usrsctp_connect()).
   // SCTP has an option for Apple, on IP connections only, to release at least
   // one of the locks before calling a packet output routine; with changes to
   // the underlying SCTP stack this might remove the need to use an async proxy.
-  if ((0 /*peer->IsSTSThread()*/)) {
+  if ((false /*peer->IsSTSThread()*/)) {
     res = peer->SendPacket(static_cast<unsigned char *>(buffer), length, false);
   } else {
     auto *data = new unsigned char[length];
     memcpy(data, buffer, length);
     // Commented out since we have to Dispatch SendPacket to avoid deadlock"
     // res = -1;
 
     // XXX It might be worthwhile to add an assertion against the thread
--- a/netwerk/test/PropertiesTest.cpp
+++ b/netwerk/test/PropertiesTest.cpp
@@ -69,17 +69,17 @@ main(int argc, char* argv[])
     return 1;
   }
   ret = props->Load(in);
   if (NS_FAILED(ret)) {
     printf("cannot load properties\n");
     return 1;
   }
   int i = 1;
-  while (1) {
+  while (true) {
     char name[16];
     name[0] = 0;
     SprintfLiteral(name, "%d", i);
     nsAutoString v;
     ret = props->GetStringProperty(nsDependentCString(name), v);
     if (NS_FAILED(ret) || (!v.Length())) {
       break;
     }