Open Bug 2082993 Opened 1 month ago Updated 1 month ago

Initialize StructuredPrinter::pendingIndent_ in js/public/Printer.h

Categories

(Core :: JavaScript Engine, task, P3)

task

Tracking

()

People

(Reporter: mgaudet, Unassigned, Mentored)

Details

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

Filing as a good first bug to learn workflows.

StructuredPrinter in js/public/Printer.h has a member that is never given a value:

bool pendingIndent_;

The constructor initializes out_ and indentAmount_ but not pendingIndent_. Because of that, the first output can read an indeterminate bool. In js/src/vm/Printer.cpp, putWithMaybeIndent() tests 'if (pendingIndent_)' before anything has written the field: putBreak() and put() are the only writers, and both run after that read on a fresh printer.

The fix is a default member initializer, so the field starts out false:

bool pendingIndent_ = false;

Link to the code:
https://searchfox.org/firefox-main/source/js/public/Printer.h

To verify the fix:

./mach build faster
./mach jsapi-tests --args 'StructuredPrinter'
./mach lint -l clang-format js/public/Printer.h

Note: this is only a one-line change, so no new test is required. Use the wasm dump paths (js/src/wasm/WasmDump.cpp) if you want a manual check that the first line of output is not indented.

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.

Severity: -- → N/A
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.