Skip to content

Coverity: avoid a string copy in ArgParser - #13849

Open
brbzull0 wants to merge 1 commit into
apache:masterfrom
brbzull0:coverity-1688253-argparser-move
Open

brbzull0 wants to merge 1 commit into
apache:masterfrom
brbzull0:coverity-1688253-argparser-move

Conversation

@brbzull0

Copy link
Copy Markdown
Contributor

append_option_data() copies env_value into the per-option state when an option that declares an environment variable is given without a value. env_value is a local of that occurrence and is not read after the copy, so this moves it instead. set_env() takes its own copy of the value earlier in the same block.

Coverity CID: 1688253

What changes: the copy-assignment at that line becomes a move-assignment. The ArgParser test cases in test_tscore pass before and after.

What this PR does not do: the other copies of env_value in append_option_data() and Command::parse() stay as they are. The value is read again after each of them (the bare-option state after set_env(), and the fill loop in parse()), so moving there would be wrong.

append_option_data() copied env_value into the per-option state on a
bare occurrence, but env_value is not read again after that, so move
it instead. set_env() has already copied the value by then.

Coverity CID: 1688253
@brbzull0 brbzull0 added this to the 11.0.0 milestone Oct 16, 2026
@brbzull0 brbzull0 self-assigned this Oct 16, 2026
@brbzull0
brbzull0 requested a balanced review from Copilot October 16, 2026 10:03
@brbzull0
brbzull0 marked this pull request as ready for review October 16, 2026 10:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The moved value has no subsequent reads, and set_env() retains an independent copy.

0 open findings

What changed in this PR

Removes an unnecessary string copy in ArgParser without changing parsing behavior.

Changes:

  • Moves the local environment value into per-option state after its final use.
  • Leaves copies needed by later reads unchanged.
File Description
src/​tscore/​ArgParser.cc Replaces one copy assignment with a move assignment.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants