Open Bug 2051535 Opened 4 months ago Updated 1 month ago

Remove dead rv assignments in nsCommandManager.cpp

Categories

(Core :: DOM: UI Events & Focus Handling, task)

task

Tracking

()

People

(Reporter: Sylvestre, Unassigned, Mentored)

References

(Blocks 1 open bug)

Details

(Keywords: good-first-bug, Whiteboard: [lang=c++])

Attachments

(1 external file)

Filing as a good first bug to learn workflows.

The clang static analyzer (scan-build) found dead assignments to rv in nsCommandManager.cpp. In both GetCommandState and DoCommand, the return value of GetControllerForCommand(...) is stored in rv, but rv is never read before being overwritten later in the function (the code branches on controller instead). The initial assignment to rv is therefore dead.

The fix is to not capture the return value into rv at that call site, and declare nsresult rv; where it is first actually used (its first real assignment). Apply the same change in both functions.

Link to the code:
https://searchfox.org/mozilla-central/source/dom/commandhandler/nsCommandManager.cpp#149
https://searchfox.org/mozilla-central/source/dom/commandhandler/nsCommandManager.cpp#171

To verify the fix:

./mach build dom/commandhandler

The change should not alter behavior: the function results already depend on the later (live) assignments to rv, not the dead initial one.

Tutorial to contribute:
https://firefox-source-docs.mozilla.org/contributing/contribution_quickref.html
https://firefox-source-docs.mozilla.org/contributing/stack_quickref.html

Please don't ask for the bug to be assigned. It will be automatically assigned to the first patch.

Mentor: sledru
Assignee: nobody → phuctran3289
Status: NEW → ASSIGNED

This good-first-bug hasn't had any activity for 2 months, it is automatically unassigned.
For more information, please visit BugBot documentation.

Assignee: phuctran3289 → nobody
Status: ASSIGNED → NEW
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: