Skip to content

CID_69168: Fix Coverity defects (6 files) - #359

Open
rdkdevpilot wants to merge 7 commits into
developfrom
topic/CID_69168
Open

rdkdevpilot wants to merge 7 commits into
developfrom
topic/CID_69168

Conversation

@rdkdevpilot

Copy link
Copy Markdown

Automated Fix for Coverity Defects

Triggered by: Gururaja ErodeSriranganRamlingham

Fixed Files

File Line(s) CIDs Checker Types Description
plugin/gnome/NetworkManagerGnomeUtils.cpp L277, L278, L279, L395, L429 60777, 60778, 60780, 60774, 69136 COPY_INSTEAD_OF_MOVE Variable copied when it could be moved
plugin/NetworkManagerConnectivity.cpp L281, L658, L748 60913, 69103, 69165 COPY_INSTEAD_OF_MOVE Variable copied when it could be moved
plugin/gnome/NetworkManagerGnomeProxy.cpp L370, L595, L669, L744 58433, 69385, 69154, 69155 COPY_INSTEAD_OF_MOVE Variable copied when it could be moved
plugin/gnome/gdbus/NetworkManagerGdbusUtils.cpp L755 69168 COPY_INSTEAD_OF_MOVE Variable copied when it could be moved
plugin/gnome/NetworkManagerGnomeEvents.cpp L114, L190, L409, L649, L970, L977 69116, 69296, 58410, 69124, 69297, 58408 COPY_INSTEAD_OF_MOVE Variable copied when it could be moved
plugin/NetworkManagerStunClient.cpp L233 58334 COPY_INSTEAD_OF_MOVE Variable copied when it could be moved

Fix Summaries

plugin/gnome/NetworkManagerGnomeUtils.cpp

The fix correctly addresses the COPY_INSTEAD_OF_MOVE Coverity defect by applying std::move() to local string variables at the point where they are assigned to their final destinations. All four changes are valid: (1) wifiIfname, ethIfname, and deviceHostname in getDeviceProperties() are local variables that are no longer used after the move assignments, and the subsequent NMLOG_INFO correctly reads from the destination members (m_wlanifname, m_ethifname, m_deviceHostname) rather than the moved-from sources; (2) line in readPersistentHostname() is a local variable not used after the move assignment to hostname, and the subsequent NMLOG_INFO correctly reads from hostname; (3) hwAddr in resolveGatewayMac() is a local variable not used after the move assignment to mac, and the subsequent NMLOG_INFO correctly reads from mac. No new defects are introduced, no logic is broken, no unnecessary abstractions are added, and the changes are minimal and targeted.

plugin/NetworkManagerConnectivity.cpp

The fix correctly applies std::move() to three local std::string variables (interface/defaultIface) that are passed by value to functions and not used after the call. All three changes are correct: (1) moving 'interface' into checkCurlResponse() in the TestConnectivity constructor where it's the last use, (2) moving 'defaultIface' into ReportInternetStatusChange() where it's the last use, and (3) moving 'defaultIface' into the TestConnectivity constructor in the ideal-case branch where it's not used afterward. The m_switchToInitial branch correctly retains a copy since defaultIface is used again after the TestConnectivity construction. No logic is broken and no new defects are introduced.

plugin/gnome/NetworkManagerGnomeProxy.cpp

All four std::move() additions correctly address COPY_INSTEAD_OF_MOVE defects. The moved variables are not accessed after the move in each case. The fix on line 595 applies std::move() to a const string, which is technically a no-op for move semantics (the copy constructor will still be invoked), but this does not introduce any new defect or break any logic — it simply fails to optimize that particular case. All other changes are effective and correct.

plugin/gnome/gdbus/NetworkManagerGdbusUtils.cpp

The fix correctly addresses the COPY_INSTEAD_OF_MOVE defect by replacing hostname = line with hostname = std::move(line) at line 755. After the two erase operations, line is a fully processed local string that is no longer needed — moving it into hostname avoids an unnecessary heap allocation and copy. The moved-from line is not accessed after the assignment; hostname.c_str() is used in the subsequent log call, which is correct. The change is minimal (one line), introduces no new defects, preserves all existing logic and return values, and is the canonical fix for this defect type.

plugin/gnome/NetworkManagerGnomeEvents.cpp

The fix correctly applies std::move() to local string variables at their last point of use before being passed to functions that take by value. All six changes are verified: the moved variables are not accessed after the move in any execution path, the if/else branches are correctly analyzed (notably the addrString move in the isIPv6LinkLocal branch does not affect the else-if/else branches), and no new defects are introduced. The fix is minimal and directly addresses the COPY_INSTEAD_OF_MOVE defect.

plugin/NetworkManagerStunClient.cpp

The fix correctly addresses the COPY_INSTEAD_OF_MOVE defect. In the original code, s was declared as std::string const s, which prevented it from being moved. The fix removes the const qualifier (making s a non-const std::string) and then uses std::move(s) when inserting into already_seen. This is the correct and minimal fix: s is used first in already_seen.find(s) (which requires a valid string), and only after that check passes and the address is processed does std::move(s) transfer ownership into the set, avoiding an unnecessary copy. The variable s is not used after the move, so there is no use-after-move issue. The indentation differences in the diff are cosmetic and noted as already verified by clang-format. No new defects are introduced, existing logic is fully preserved, and the change is minimal and targeted.

Defect ID: 4c509ab1-5c48-4af5-af00-78f481c18969
Defect ID: 47644ad7-d7a1-49ae-a9fa-e7923c7c535b
Defect ID: 1e106169-87f4-4203-af75-934ba8a7968e
Defect ID: 109513fb-c379-45ab-bf2a-7836ca582019
Defect ID: ef93233f-dbb8-4a26-a5ef-a8f453fbedce
Defect ID: fc25794f-feee-47cf-b831-6ec1415d2181

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.

🟡 Changes recommended

The proxy’s const local makes std::move ineffective, leaving one Coverity finding unresolved.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR addresses Coverity COPY_INSTEAD_OF_MOVE findings across six NetworkManager plugin files.

Changes:

  • Adds move semantics for local strings and parsed values.
  • Optimizes connectivity, event, hostname, proxy, and STUN handling.
  • Removes const where needed for effective moves.
File summaries
File Summary
plugin/NetworkManagerStunClient.cpp Moves resolved addresses into the deduplication set.
plugin/NetworkManagerConnectivity.cpp Moves interface names into connectivity operations.
plugin/gnome/NetworkManagerGnomeUtils.cpp Moves parsed properties, hostname, and MAC values.
plugin/gnome/NetworkManagerGnomeProxy.cpp Moves proxy and activation data; lastConnectedSSID remains const, making one move ineffective.
plugin/gnome/NetworkManagerGnomeEvents.cpp Moves event and cache payloads.
plugin/gnome/gdbus/NetworkManagerGdbusUtils.cpp Moves the parsed hostname.
Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 1
  • Review effort level: Lite

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

Comment thread plugin/gnome/NetworkManagerGnomeProxy.cpp
Copilot AI lite review requested due to automatic review settings October 26, 2026 17:03

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 changes resolve the targeted Coverity findings without behavioral issues; only a minor indentation nit remains.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Low severity Fix over-indented declaration in loop body

plugin/​NetworkManagerStunClient.cpp:217

This new declaration is indented four spaces deeper than the surrounding loop body (the preceding if is at six spaces), so the change does not follow the indentation used throughout this file. Align it with the other statements in the loop.

This issue also appears on line 233 of the same file.

1 resolved since last review

Review effort: Lite

This branch has not been deployed

No deployments
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.

4 participants