Closed Bug 1274415 Opened 3 years ago Closed 3 years ago

Fix -Wshadow warnings in caps/ directory

Categories

(Core :: Security: CAPS, defect)

defect
Not set

Tracking

()

RESOLVED FIXED
mozilla49
Tracking Status
firefox49 --- fixed

People

(Reporter: cpeterson, Assigned: cpeterson)

References

Details

Attachments

(1 file)

Fix -Wshadow warnings in caps/ directory and remove warning suppression flag.

caps/BasePrincipal.cpp:562:28 [-Wshadow] declaration shadows a local variable
caps/nsScriptSecurityManager.cpp:675:18 [-Wshadow] declaration shadows a local variable
caps/nsScriptSecurityManager.cpp:854:14 [-Wshadow] declaration shadows a local variable
Attachment #8754556 - Flags: review?(dveditz)
Comment on attachment 8754556 [details] [diff] [review]
Wshadow_caps.patch

Review of attachment 8754556 [details] [diff] [review]:
-----------------------------------------------------------------

Some notes on the code changes:

::: caps/BasePrincipal.cpp
@@ -550,5 @@
>    // we shouldn't make a codebase principal for it.
>    bool inheritsPrincipal;
>    nsresult rv = NS_URIChainHasFlags(aURI, nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT,
>                                      &inheritsPrincipal);
> -  nsCOMPtr<nsIPrincipal> principal;

The `principal` variable declared below shadows this variable's name, but this `principal` variable is actually unused.

::: caps/nsScriptSecurityManager.cpp
@@ -676,1 @@
>          NS_ENSURE_SUCCESS(rv, false);

We can reuse an `rv` variable declared above. The value does not need to be preserved after this NS_ENSURE_SUCCESS() call.

@@ -855,3 @@
>          rv = NS_URIChainHasFlags(targetBaseURI,
>                                   nsIProtocolHandler::URI_CROSS_ORIGIN_NEEDS_WEBAPPS_PERM,
>                                   &hasFlags);

Reuse `hasFlags` declared above. Other calls to NS_URIChainHasFlags() in this function also reuse `hasFlags`. This is safe because the variable's value is not used after each `if (hasFlags)` check below.
Comment on attachment 8754556 [details] [diff] [review]
Wshadow_caps.patch

Review of attachment 8754556 [details] [diff] [review]:
-----------------------------------------------------------------

looks good, r=dveditz
Attachment #8754556 - Flags: review?(dveditz) → review+
https://hg.mozilla.org/mozilla-central/rev/eeb73478d984
Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla49
You need to log in before you can comment on or make changes to this bug.