Fix 6 PVS-Studio static analyzer findings#27035
Open
SufficientDaikon wants to merge 1 commit intoPowerShell:masterfrom
Open
Fix 6 PVS-Studio static analyzer findings#27035SufficientDaikon wants to merge 1 commit intoPowerShell:masterfrom
SufficientDaikon wants to merge 1 commit intoPowerShell:masterfrom
Conversation
5 tasks
Address items 1, 2, 5, 6, 7, 9 from the PVS-Studio report in PowerShell#25289: - Item 9: Fix ?? operator precedence in StringUtil.cs — appendStr length was silently ignored in capacity calculation - Item 2: Add volatile to logInitialized in CimCmdlets/Utils.cs for safe double-checked locking - Item 6: Move RunspaceRef null check before first use in ConsoleHost.cs to prevent NullReferenceException - Item 1: Add null guard for GetCimInstanceParameter return value in CimGetInstance.cs - Item 5: Use null-conditional on Members["Module"] access in ShowCommandCommandInfo.cs - Item 7: Split vd null check from type check in typeDataQuery.cs to prevent NullReferenceException in trace logging Items 3, 4, 8, 10 are intentionally left — they require design decisions, affect auto-generated code, or would be breaking changes. Addresses PowerShell#25289 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
514fb65 to
881d2bb
Compare
This was referenced Mar 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary
Fixes 6 of the 10 PVS-Studio static analyzer findings reported in #25289. The remaining 4 items require design decisions, affect auto-generated code, or would be breaking changes — rationale below.
Fixed Items
ConsoleHost.csRunspaceRefused before null checkCimGetInstance.csGetCimInstanceParametercan return null, dereferencedtypeDataQuery.csvd.mainControlaccessed whenvd == nullStringUtil.cs??operator precedence —appendStrlength silently ignoredShowCommandCommandInfo.csMembers["Module"]without null-conditional?.CimCmdlets/Utils.csvolatileItem 6 — Null check order in ConsoleHost.cs (High)
Item 1 — Null dereference in CimGetInstance.cs (High)
Item 7 — Null dereference in typeDataQuery.cs (High)
Item 9 — Operator precedence in StringUtil.cs (Medium)
Item 5 — Null access in ShowCommandCommandInfo.cs (Medium)
Item 2 — Missing volatile in Utils.cs (Low)
Skipped Items
Note
4 items intentionally left for maintainer guidance. Each requires a design decision beyond a mechanical fix.
Skipped items with rationale
GetEventCommand.cssuppressOpenerhas no format placeholders — may be intentional designNew-Object.csFullLanguageswitch case — may be deliberate fall-throughxmlSerializer.autogen.csCommand.csPipelineResultTypesFlags enum values — changing is a public API breaking changePR Context
Addresses #25289 (items 1, 2, 5, 6, 7, 9). These are defensive null-checks and correctness fixes in code paths that would manifest as
NullReferenceExceptioncrashes or silent miscalculation under specific conditions.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header