From 74adf910baeae879d5a32ab420dafadbdf31d77b Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Fri, 29 Apr 2022 09:14:11 +0000 Subject: [PATCH] Bug 1766377 - Fix sign-compare warnings related to IDL constants. r=anti-tracking-reviewers,necko-reviewers,kershaw,timhuang dom/network/TCPSocket.cpp(973,38): error: comparison of integers of different signs: 'uint32_t' (aka 'unsigned int') and 'nsISocketTransport::(unnamed enum at obj-aarch64-pc-mingw32/dist/include/nsISocketTransport.h:102:3)' [-Werror,-Wsign-compare] if (static_cast(aStatus) != ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ dom/security/ReferrerInfo.cpp(216,26): error: comparison of integers of different signs: 'uint32_t' (aka 'unsigned int') and 'nsIWebProgressListener::(unnamed enum at obj-aarch64-pc-mingw32/dist/include/nsIWebProgressListener.h:41:3)' [-Werror,-Wsign-compare] rejectedReason != ~~~~~~~~~~~~~~ ^ toolkit/components/antitracking/StorageAccess.cpp(175,23): error: comparison of integers of different signs: 'uint32_t' (aka 'unsigned int') and 'nsIWebProgressListener::(unnamed enum at obj-aarch64-pc-mingw32/dist/include/nsIWebProgressListener.h:41:3)' [-Werror,-Wsign-compare] if (aRejectedReason == ~~~~~~~~~~~~~~~ ^ toolkit/components/antitracking/StorageAccess.cpp(415,26): error: comparison of integers of different signs: 'uint32_t' (aka 'unsigned int') and 'nsIWebProgressListener::(unnamed enum at obj-aarch64-pc-mingw32/dist/include/nsIWebProgressListener.h:41:3)' [-Werror,-Wsign-compare] aRejectedReason == ~~~~~~~~~~~~~~~ ^ toolkit/components/antitracking/StorageAccess.cpp(428,26): error: comparison of integers of different signs: 'uint32_t' (aka 'unsigned int') and 'nsIWebProgressListener::(unnamed enum at obj-aarch64-pc-mingw32/dist/include/nsIWebProgressListener.h:41:3)' [-Werror,-Wsign-compare] return aRejectedReason == ~~~~~~~~~~~~~~~ ^ Differential Revision: https://phabricator.services.mozilla.com/D144693 --- dom/network/TCPSocket.cpp | 2 +- dom/security/ReferrerInfo.cpp | 3 +- .../antitracking/ContentBlockingNotifier.cpp | 60 +++++++++++++------ .../components/antitracking/StorageAccess.cpp | 21 ++++--- 4 files changed, 59 insertions(+), 27 deletions(-) diff --git a/dom/network/TCPSocket.cpp b/dom/network/TCPSocket.cpp index 9af1e6f702db..e25ec5a18ee5 100644 --- a/dom/network/TCPSocket.cpp +++ b/dom/network/TCPSocket.cpp @@ -971,7 +971,7 @@ NS_IMETHODIMP TCPSocket::OnTransportStatus(nsITransport* aTransport, nsresult aStatus, int64_t aProgress, int64_t aProgressMax) { if (static_cast(aStatus) != - nsISocketTransport::STATUS_CONNECTED_TO) { + static_cast(nsISocketTransport::STATUS_CONNECTED_TO)) { return NS_OK; } diff --git a/dom/security/ReferrerInfo.cpp b/dom/security/ReferrerInfo.cpp index ce9b0ec008a7..103f7cddd428 100644 --- a/dom/security/ReferrerInfo.cpp +++ b/dom/security/ReferrerInfo.cpp @@ -214,7 +214,8 @@ ReferrerPolicy ReferrerInfo::GetDefaultReferrerPolicy(nsIHttpChannel* aChannel, !ContentBlocking::ShouldAllowAccessFor(aChannel, aURI, &rejectedReason) && rejectedReason != - nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN; + static_cast( + nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN); // Here we intentionally do not notify about the rejection reason, if any // in order to avoid this check to have any visible side-effects (e.g. a // web console report.) diff --git a/toolkit/components/antitracking/ContentBlockingNotifier.cpp b/toolkit/components/antitracking/ContentBlockingNotifier.cpp index 2e1716448a09..965eef17de3a 100644 --- a/toolkit/components/antitracking/ContentBlockingNotifier.cpp +++ b/toolkit/components/antitracking/ContentBlockingNotifier.cpp @@ -115,15 +115,23 @@ void ReportBlockingToConsole(uint64_t aWindowID, nsIURI* aURI, MOZ_ASSERT( aRejectedReason == 0 || aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION || + static_cast( + nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION) || aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER || + static_cast( + nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER) || aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER || + static_cast( + nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER) || aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN || - aRejectedReason == nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL || - aRejectedReason == nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN); + static_cast( + nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN) || + aRejectedReason == + static_cast( + nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL) || + aRejectedReason == + static_cast( + nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN)); if (aURI->SchemeIs("chrome") || aURI->SchemeIs("about")) { return; @@ -409,15 +417,23 @@ void ContentBlockingNotifier::OnDecision(nsIChannel* aChannel, MOZ_ASSERT( aRejectedReason == 0 || aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION || + static_cast( + nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION) || aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER || + static_cast( + nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER) || aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER || + static_cast( + nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER) || aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN || - aRejectedReason == nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL || - aRejectedReason == nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN); + static_cast( + nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN) || + aRejectedReason == + static_cast( + nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL) || + aRejectedReason == + static_cast( + nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN)); MOZ_ASSERT(aDecision == BlockingDecision::eBlock || aDecision == BlockingDecision::eAllow); @@ -440,15 +456,23 @@ void ContentBlockingNotifier::OnDecision(nsPIDOMWindowInner* aWindow, MOZ_ASSERT( aRejectedReason == 0 || aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION || + static_cast( + nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION) || aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER || + static_cast( + nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER) || aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER || + static_cast( + nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER) || aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN || - aRejectedReason == nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL || - aRejectedReason == nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN); + static_cast( + nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN) || + aRejectedReason == + static_cast( + nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL) || + aRejectedReason == + static_cast( + nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN)); MOZ_ASSERT(aDecision == BlockingDecision::eBlock || aDecision == BlockingDecision::eAllow); diff --git a/toolkit/components/antitracking/StorageAccess.cpp b/toolkit/components/antitracking/StorageAccess.cpp index c22aa5247bae..d23e50283a3a 100644 --- a/toolkit/components/antitracking/StorageAccess.cpp +++ b/toolkit/components/antitracking/StorageAccess.cpp @@ -165,15 +165,18 @@ static StorageAccess InternalStorageAllowedCheck( // We want to have a partitioned storage only for trackers. if (aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER || + static_cast( + nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER) || aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER) { + static_cast( + nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER)) { return StorageAccess::ePartitionTrackersOrDeny; } // We want to have a partitioned storage for all third parties. if (aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN) { + static_cast( + nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN)) { return StorageAccess::ePartitionForeignOrDeny; } @@ -409,11 +412,14 @@ bool ShouldPartitionStorage(StorageAccess aAccess) { bool ShouldPartitionStorage(uint32_t aRejectedReason) { return aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER || + static_cast( + nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER) || aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER || + static_cast( + nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER) || aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN; + static_cast( + nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN); } bool StoragePartitioningEnabled(StorageAccess aAccess, @@ -426,7 +432,8 @@ bool StoragePartitioningEnabled(StorageAccess aAccess, bool StoragePartitioningEnabled(uint32_t aRejectedReason, nsICookieJarSettings* aCookieJarSettings) { return aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN && + static_cast( + nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN) && aCookieJarSettings->GetCookieBehavior() == nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN; }