Bug 1575924 - Apply readability-implicit-bool-conversion to Resist Fingerpritning code r=timhuang
authorTom Ritter <tom@mozilla.com>
Fri, 23 Aug 2019 13:12:45 +0000
changeset 489582 88adfeed22650fee5b07b34af6e3cc289bea5db1
parent 489581 c876ad3fbde8cc8f622389b7835b53cbab9d773c
child 489583 bcf1874cde5435ef9ca8503b3319c3ead7740f5a
push id36478
push userdvarga@mozilla.com
push dateFri, 23 Aug 2019 21:49:00 +0000
treeherdermozilla-central@9f96b6821f1d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstimhuang
bugs1575924
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1575924 - Apply readability-implicit-bool-conversion to Resist Fingerpritning code r=timhuang Depends on D40227 Differential Revision: https://phabricator.services.mozilla.com/D43106
toolkit/components/resistfingerprinting/nsRFPService.cpp
--- a/toolkit/components/resistfingerprinting/nsRFPService.cpp
+++ b/toolkit/components/resistfingerprinting/nsRFPService.cpp
@@ -340,17 +340,17 @@ nsresult nsRFPService::RandomMidpoint(lo
 
   nsCString hashResult = cache->Get(extraClampedTime, aContextMixin);
 
   if (hashResult.Length() != HASH_DIGEST_SIZE_BYTES) {  // Cache Miss =(
     // If someone has pased in the testing-only parameter, replace our seed with
     // it
     if (aSecretSeed != nullptr) {
       StaticMutexAutoLock lock(sLock);
-      if (sSecretMidpointSeed) {
+      if (sSecretMidpointSeed != nullptr) {
         delete[] sSecretMidpointSeed;
       }
       sSecretMidpointSeed = new uint8_t[kSeedSize];
       memcpy(sSecretMidpointSeed, aSecretSeed, kSeedSize);
     }
 
     // If we don't have a seed, we need to get one.
     if (MOZ_UNLIKELY(!sSecretMidpointSeed)) {
@@ -726,26 +726,26 @@ nsresult nsRFPService::Init() {
   NS_ENSURE_SUCCESS(rv, rv);
 #endif
 
   Preferences::RegisterCallbacks(PREF_CHANGE_METHOD(nsRFPService::PrefChanged),
                                  gCallbackPrefs, this);
 
   // We backup the original TZ value here.
   const char* tzValue = PR_GetEnv("TZ");
-  if (tzValue) {
+  if (tzValue != nullptr) {
     mInitialTZValue = nsCString(tzValue);
   }
 
   // Call Update here to cache the values of the prefs and set the timezone.
   UpdateRFPPref();
 
   // Create the LRU Cache when we initialize, to avoid accidently trying to
   // create it (and call ClearOnShutdown) on a non-main-thread
-  if (!sCache) {
+  if (sCache == nullptr) {
     sCache = new LRUCache();
   }
 
   return rv;
 }
 
 // This function updates only timing-related fingerprinting items
 void nsRFPService::UpdateTimers() {
@@ -783,23 +783,23 @@ void nsRFPService::UpdateRFPPref() {
     // We will not touch the TZ value if 'privacy.resistFingerprinting' is false
     // during the time of initialization.
     if (!mInitialTZValue.IsEmpty()) {
       nsAutoCString tzValue = NS_LITERAL_CSTRING("TZ=") + mInitialTZValue;
       static char* tz = nullptr;
 
       // If the tz has been set before, we free it first since it will be
       // allocated a new value later.
-      if (tz) {
+      if (tz != nullptr) {
         free(tz);
       }
       // PR_SetEnv() needs the input string been leaked intentionally, so
       // we copy it here.
       tz = ToNewCString(tzValue);
-      if (tz) {
+      if (tz != nullptr) {
         PR_SetEnv(tz);
       }
     } else {
 #if defined(XP_WIN)
       // For Windows, we reset the TZ to an empty string. This will make Windows
       // to use its system timezone.
       PR_SetEnv("TZ=");
 #else
@@ -838,17 +838,17 @@ void nsRFPService::StartShutdown() {
   }
   Preferences::UnregisterCallbacks(
       PREF_CHANGE_METHOD(nsRFPService::PrefChanged), gCallbackPrefs, this);
 }
 
 /* static */
 void nsRFPService::MaybeCreateSpoofingKeyCodes(const KeyboardLangs aLang,
                                                const KeyboardRegions aRegion) {
-  if (!sSpoofingKeyboardCodes) {
+  if (sSpoofingKeyboardCodes == nullptr) {
     sSpoofingKeyboardCodes =
         new nsDataHashtable<KeyboardHashKey, const SpoofingKeyboardCode*>();
   }
 
   if (KeyboardLang::EN == aLang) {
     switch (aRegion) {
       case KeyboardRegion::US:
         MaybeCreateSpoofingKeyCodesForEnUS();
@@ -936,26 +936,26 @@ bool nsRFPService::GetSpoofedKeyCodeInfo
     const dom::Document* aDoc, const WidgetKeyboardEvent* aKeyboardEvent,
     SpoofingKeyboardCode& aOut) {
   MOZ_ASSERT(aKeyboardEvent);
 
   KeyboardLangs keyboardLang = RFP_DEFAULT_SPOOFING_KEYBOARD_LANG;
   KeyboardRegions keyboardRegion = RFP_DEFAULT_SPOOFING_KEYBOARD_REGION;
   // If the document is given, we use the content language which is get from the
   // document. Otherwise, we use the default one.
-  if (aDoc) {
+  if (aDoc != nullptr) {
     nsAutoString language;
     aDoc->GetContentLanguage(language);
 
     // If the content-langauge is not given, we try to get langauge from the
     // HTML lang attribute.
     if (language.IsEmpty()) {
       dom::Element* elm = aDoc->GetHtmlElement();
 
-      if (elm) {
+      if (elm != nullptr) {
         elm->GetLang(language);
       }
     }
 
     // If two or more languages are given, per HTML5 spec, we should consider
     // it as 'unknown'. So we use the default one.
     if (!language.IsEmpty() && !language.Contains(char16_t(','))) {
       language.StripWhitespace();
@@ -970,17 +970,17 @@ bool nsRFPService::GetSpoofedKeyCodeInfo
 
   if (keyIdx == KEY_NAME_INDEX_USE_STRING) {
     keyName = aKeyboardEvent->mKeyValue;
   }
 
   KeyboardHashKey key(keyboardLang, keyboardRegion, keyIdx, keyName);
   const SpoofingKeyboardCode* keyboardCode = sSpoofingKeyboardCodes->Get(key);
 
-  if (keyboardCode) {
+  if (keyboardCode != nullptr) {
     aOut = *keyboardCode;
     return true;
   }
 
   return false;
 }
 
 /* static */
@@ -992,21 +992,21 @@ bool nsRFPService::GetSpoofedModifierSta
   // For modifier or control keys, we don't need to hide its modifier states.
   if (aKeyboardEvent->mKeyNameIndex != KEY_NAME_INDEX_USE_STRING) {
     return false;
   }
 
   // We will spoof the modifer state for Alt, Shift, and AltGraph.
   // We don't spoof the Control key, because it is often used
   // for command key combinations in web apps.
-  if (aModifier & (MODIFIER_ALT | MODIFIER_SHIFT | MODIFIER_ALTGRAPH)) {
+  if ((aModifier & (MODIFIER_ALT | MODIFIER_SHIFT | MODIFIER_ALTGRAPH)) != 0) {
     SpoofingKeyboardCode keyCodeInfo;
 
     if (GetSpoofedKeyCodeInfo(aDoc, aKeyboardEvent, keyCodeInfo)) {
-      aOut = keyCodeInfo.mModifierStates & aModifier;
+      aOut = ((keyCodeInfo.mModifierStates & aModifier) != 0);
       return true;
     }
   }
 
   return false;
 }
 
 /* static */
@@ -1070,17 +1070,17 @@ void nsRFPService::PrefChanged(const cha
     }
 #endif
   }
 }
 
 NS_IMETHODIMP
 nsRFPService::Observe(nsISupports* aObject, const char* aTopic,
                       const char16_t* aMessage) {
-  if (!strcmp(NS_XPCOM_SHUTDOWN_OBSERVER_ID, aTopic)) {
+  if (strcmp(NS_XPCOM_SHUTDOWN_OBSERVER_ID, aTopic) == 0) {
     StartShutdown();
   }
 #if defined(XP_WIN)
   else if (!strcmp(PROFILE_INITIALIZED_TOPIC, aTopic)) {
     // If we're e10s, then we don't need to run this, since the child process
     // will simply inherit the environment variable from the parent process, in
     // which case it's unnecessary to call _tzset().
     if (XRE_IsParentProcess() && !XRE_IsE10sParentProcess()) {