René's URL Explorer Experiment


Title: Some issues found by static analyzer · Issue #25289 · PowerShell/PowerShell · GitHub

Open Graph Title: Some issues found by static analyzer · Issue #25289 · PowerShell/PowerShell

X Title: Some issues found by static analyzer · Issue #25289 · PowerShell/PowerShell

Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerShell 5.1 and PowerShell. Steps to reprodu...

Open Graph Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...

X Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...

Opengraph URL: https://github.com/PowerShell/PowerShell/issues/25289

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Some issues found by static analyzer","articleBody":"### Prerequisites\n\n- [x] Write a descriptive title.\n- [x] Make sure you are able to repro it on the [latest released version](https://github.com/PowerShell/PowerShell/releases)\n- [x] Search the existing issues.\n- [x] Refer to the [FAQ](https://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md).\n- [x] Refer to [Differences between Windows PowerShell 5.1 and PowerShell](https://learn.microsoft.com/powershell/scripting/whats-new/differences-from-windows-powershell).\n\n### Steps to reproduce\n\nThis issues found by static analyzer, so we don't have steps to reproduce.\n\n### Expected behavior\n\n```console\nThe described errors are not in the project source code\n```\n\n### Actual behavior\n\n```console\nThe described errors are in the project source code\n```\n\n### Error details\n\n```console\n\n```\n\n### Environment data\n\n```powershell\nNo environment\n```\n\n### Visuals\n\nHello! We released [an article](https://pvs-studio.com/en/blog/posts/csharp/1243/) with checking this project with PVS-Studio static code analyzer and found some interesting bugs. Their description below.\n\n1. src\\Microsoft.Management.Infrastructure.CimCmdlets\\CimGetInstance.cs, line 168\n\n```cs\n....\ncase CimBaseCommand.CimInstanceSessionSet:\n\tCimInstance instance = GetCimInstanceParameter(cmdlet);\n\tnameSpace = ConstValue.GetNamespace(instance.CimSystemProperties.Namespace);\n\t    foreach (CimSessionProxy proxy in proxys)\n\t    {\n\t        proxy.GetInstanceAsync(nameSpace, instance);\n\t    }\n....\n```\n\nPVS-Studio Message:\n[V3080](https://pvs-studio.com/en/docs/warnings/v3080/) Possible null dereference. Consider inspecting 'instance'. CimGetInstance.cs 168\n\n`instance` is nullable because `GetCimInstance` method can return `null`:\n\n```cs\nprotected static CimInstance GetCimInstanceParameter(CimBaseCommand cmdlet)\n{\n\tif (cmdlet is GetCimInstanceCommand)\n\t{\n\t\treturn (cmdlet as GetCimInstanceCommand).CimInstance;\n\t}\n\t\n\telse if (cmdlet is RemoveCimInstanceCommand)\n\t{\n\t\treturn (cmdlet as RemoveCimInstanceCommand).CimInstance;\n\t}\n\t\n\telse if (cmdlet is SetCimInstanceCommand)\n\t{\n\t\treturn (cmdlet as SetCimInstanceCommand).CimInstance;\n\t}\n\treturn null;\n}\n```\n\n2. src\\Microsoft.Management.Infrastructure.CimCmdlets\\Utils.cs, line 305\n\n```cs\nprivate static bool logInitialized = false;\n....\nif (!logInitialized)\n{\n\tlock (logLock)\n\t{\n\t\tif (!logInitialized)\n\t\t{\n\t\t\tDebugHelper.GenerateLog = File.Exists(logFile);\n\t\t\tlogInitialized = true;\n\t\t}\n\t}\n}\n....\n```\n\nPVS-Studio Message: \n[V3054](https://pvs-studio.com/en/docs/warnings/v3054) Potentially unsafe double-checked locking. Use volatile variable(s) or synchronization primitives to avoid this. Utils.cs 305\n\nHere analyzer found unsafe double-checked locking because `logInitialized` field isn't declared as `volatile`.\n\n3. src\\Microsoft.PowerShell.Commands.Diagnostics\\GetEventCommand.cs, line 1066\n\n```cs\nqueriedLogsQueryMapSuppress.Add(logName.ToLowerInvariant(),\n                                string.Format(CultureInfo.InvariantCulture, \n                                            suppressOpener, \n                                            queryId++, \n                                            logName)\n                                            );\n```\n\nPVS-Studio Message:\n[V3025](https://pvs-studio.com/en/docs/warnings/v3025/) Incorrect format. A different number of format items is expected while calling 'Format' function. Arguments not used: queryId++, logName. GetEventCommand.cs 1067\n\nHere analyzer warns about string formatting because `suppressOpener` is `\"\u003cSuppress\u003e*\"` and doesn't have any placeholders. Perhaps there should be another variable here.\n\n4. src\\Microsoft.PowerShell.Commands.Utility\\commands\\utility\\New-Object.cs, line 3002\n\n```cs\n....\nswitch (Context.LanguageMode)\n{  \n\tcase PSLanguageMode.ConstrainedLanguage:    \n\t\t....    \n\t\tbreak;  \n\tcase PSLanguageMode.NoLanguage:  \n\tcase PSLanguageMode.RestrictedLanguage:    \n\t....    \n\tbreak;\n}\n....\n```\n\nPVS-Studio Message:\n[V3002](https://pvs-studio.com/en/docs/warnings/v3002/) The switch statement does not cover all values of the 'PSLanguageMode' enum: FullLanguage. New-Object.cs 190 undefined\n\nThis switch doesn't cover all vallues of `PSLanguageMode` enumeration and doesn't have `deafult` branch.\n\n5. src\\Microsoft.PowerShell.Commands.Utility\\commands\\utility\\ShowCommand\\ShowCommandCommandInfo.cs, line 81\n```cs\n...\nthis.Module = other.Members[\"Module\"].Value as ShowCommandModuleInfo;\n...\nif (other.Members[\"Module\"]?.Value is PSObject)\n```\n\nPVS-Studio Message: \n[V3095](https://pvs-studio.com/en/docs/warnings/v3095/) The 'other.Members[\"Module\"]' object was used before it was verified against null. Check lines: 81, 91. ShowCommandCommandInfo.cs 81\n\n`other.Members` is being checked against `null` below in the code, but in this location it isn't.\n\n6. src\\Microsoft.PowerShell.ConsoleHost\\host\\msh\\ConsoleHost.cs, line 781\n\n```cs\ninternal LocalRunspace LocalRunspace\n{\n\tget\n\t{\n\t\tif (_isRunspacePushed)\n\t\t{\n\t\t\treturn RunspaceRef.OldRunspace as LocalRunspace;\n\t\t}\n\n\t\tif (RunspaceRef == null)\n\t\t{\n\t\t\treturn null;\n\t\t}\n\t\t\n\t\treturn RunspaceRef.Runspace as LocalRunspace;\n\t}\n}\n```\n\nPVS-Studio Message:\n[V3095](https://pvs-studio.com/en/docs/warnings/v3095/) The 'RunspaceRef' object was used before it was verified against null. Check lines: 781, 784. ConsoleHost.cs 781\n\nI think this message doesn't need any explanation.\n\n7. src\\System.Management.Automation\\FormatAndOutput\\common\\DisplayDatabase\\typeDataQuery.cs, line 415\n\n```cs\n....\nif (vd == null || mainControlType != vd.mainControl.GetType())\n{\n\tActiveTracer.WriteLine(\n\t\t\"NOT MATCH {0}  NAME: {1}\",\n\t\tControlBase.GetControlShapeName(vd.mainControl), \n\t\t(vd != null ? vd.name : string.Empty)\n\t);\n    continue;\n}\n....\n```\n\nPVS-Studio Message:\n[V3095](https://pvs-studio.com/en/docs/warnings/v3095/) The 'vd' object was used before it was verified against null. Check lines: 415, 415. typeDataQuery.cs 415\n\nIf `vd` will be `null` then `ControlBase.GetControlShapeName(vd.mainControl)` will lead to `NullReferenceException`.\n\n8. src\\System.Management.Automation\\cimSupport\\cmdletization\\xml\\CoreCLR\\cmdlets-over-objects.xmlSerializer.autogen.cs, line 1471\n\n```cs\nif (Reader.NodeType == System.Xml.XmlNodeType.Element)\n{\n\tUnknownNode((object)o, string.Empty);\n}\nelse\n{\n\tUnknownNode((object)o, string.Empty);\n}\n```\n\nPVS-Studio Message:\n[V3004](https://pvs-studio.com/en/docs/warnings/v3004/) The 'then' statement is equivalent to the 'else' statement. cmdlets-over-objects.xmlSerializer.autogen.cs 1471\n\nYes, just about refactoring.\n\n9. src\\System.Management.Automation\\utils\\StringUtil.cs, line 246\n\n```cs\nint capacity = length + prependStr?.Length ?? 0 + appendStr?.Length ?? 0;\n```\n\nPVS-Studio Message:\n[V3123](https://pvs-studio.com/en/docs/warnings/v3123/) Perhaps the '??' operator works in a different way than it was expected. Its priority is lower than priority of other operators in its left part. StringUtil.cs 246\n\nThis expression may have unexpected result because `??` operator have lower priority than `+`.\n\n10. src\\System.Management.Automation\\engine\\hostifaces\\Command.cs, line 779\n\n```cs\n[Flags]\npublic enum PipelineResultTypes\n{\n\tNone = 1,\n    Output = 2,\n    Error = 4,\n    Warning = 8,\n    Verbose = 16,\n    Debug = 32,\n    Information = 64,\n    All = 128,\n    Null = 0\n}\n```\n\nPVS-Studio Message:\n[V3121](https://pvs-studio.com/en/docs/warnings/v3121/) An enumeration 'PipelineResultTypes' was declared with 'Flags' attribute, but does not set any initializers to override default values. Command.cs 779\n\nThis `enum` is declared with `Flags` attribute but doesn't override default values so it may take an unexpected effect when combining elements. For example, result of this expression would be `PipelineResultTypes.Warning`:\n\n```cs\n_mergeUnclaimedPreviousCommandResults = PipelineResultTypes.Error |                                        PipelineResultTypes.Output;\n```","author":{"url":"https://github.com/feeelin","@type":"Person","name":"feeelin"},"datePublished":"2025-04-08T07:32:36.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/25289/PowerShell/issues/25289"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:b26f0b5d-e6bc-c9c0-3c33-ffe4bbb6041e
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idB354:3C8683:1C4F006:26B0946:6A4F249F
html-safe-nonce53d6db37253f1070718ec8b1c9ac1f7d4fe8c33ebb7bde8ff0e0b7011d6c65a8
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMzU0OjNDODY4MzoxQzRGMDA2OjI2QjA5NDY6NkE0RjI0OUYiLCJ2aXNpdG9yX2lkIjoiMzkzNjE5NzU1NTU4MzM5NDk3NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac139e2d2e0cc3c660eb4094792ee710bf524ef31f0d33ec60c777cb2016d10c27
hovercard-subject-tagissue:2978884717
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/25289/issue_layout
twitter:imagehttps://opengraph.githubassets.com/2621a3f5bf67306bb332f8d617fbc4f472d7a515e4d4a03f4391e86fab8b4641/PowerShell/PowerShell/issues/25289
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/2621a3f5bf67306bb332f8d617fbc4f472d7a515e4d4a03f4391e86fab8b4641/PowerShell/PowerShell/issues/25289
og:image:altPrerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamefeeelin
hostnamegithub.com
expected-hostnamegithub.com
Noneb92d11c0aa4a77d54ef4af1078b6a15fb5a70a215b30c4ecf28889d5a8e656d9
turbo-cache-controlno-preview
go-importgithub.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git
octolytics-dimension-user_id11524380
octolytics-dimension-user_loginPowerShell
octolytics-dimension-repository_id49609581
octolytics-dimension-repository_nwoPowerShell/PowerShell
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id49609581
octolytics-dimension-repository_network_root_nwoPowerShell/PowerShell
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release2b8f23afb982271f1b22258a94aede67a6b77760
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/PowerShell/PowerShell/issues/25289#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FPowerShell%2FPowerShell%2Fissues%2F25289
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FPowerShell%2FPowerShell%2Fissues%2F25289
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=PowerShell%2FPowerShell
Reloadhttps://github.com/PowerShell/PowerShell/issues/25289
Reloadhttps://github.com/PowerShell/PowerShell/issues/25289
Reloadhttps://github.com/PowerShell/PowerShell/issues/25289
Please reload this pagehttps://github.com/PowerShell/PowerShell/issues/25289
PowerShell https://github.com/PowerShell
PowerShellhttps://github.com/PowerShell/PowerShell
Notifications https://github.com/login?return_to=%2FPowerShell%2FPowerShell
Fork 8.4k https://github.com/login?return_to=%2FPowerShell%2FPowerShell
Star 54.3k https://github.com/login?return_to=%2FPowerShell%2FPowerShell
Code https://github.com/PowerShell/PowerShell
Issues 1.2k https://github.com/PowerShell/PowerShell/issues
Pull requests 285 https://github.com/PowerShell/PowerShell/pulls
Discussions https://github.com/PowerShell/PowerShell/discussions
Actions https://github.com/PowerShell/PowerShell/actions
Projects https://github.com/PowerShell/PowerShell/projects
Security and quality 3 https://github.com/PowerShell/PowerShell/security
Insights https://github.com/PowerShell/PowerShell/pulse
Code https://github.com/PowerShell/PowerShell
Issues https://github.com/PowerShell/PowerShell/issues
Pull requests https://github.com/PowerShell/PowerShell/pulls
Discussions https://github.com/PowerShell/PowerShell/discussions
Actions https://github.com/PowerShell/PowerShell/actions
Projects https://github.com/PowerShell/PowerShell/projects
Security and quality https://github.com/PowerShell/PowerShell/security
Insights https://github.com/PowerShell/PowerShell/pulse
Some issues found by static analyzerhttps://github.com/PowerShell/PowerShell/issues/25289#top
Issue-Code Cleanupthe issue is for cleaning up the code with no impact on functionalityhttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Issue-Code%20Cleanup%22
Needs-TriageThe issue is new and needs to be triaged by a work group.https://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Needs-Triage%22
Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorshttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Up-for-Grabs%22
https://github.com/feeelin
feeelinhttps://github.com/feeelin
on Apr 8, 2025https://github.com/PowerShell/PowerShell/issues/25289#issue-2978884717
latest released versionhttps://github.com/PowerShell/PowerShell/releases
FAQhttps://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md
Differences between Windows PowerShell 5.1 and PowerShellhttps://learn.microsoft.com/powershell/scripting/whats-new/differences-from-windows-powershell
an articlehttps://pvs-studio.com/en/blog/posts/csharp/1243/
V3080https://pvs-studio.com/en/docs/warnings/v3080/
V3054https://pvs-studio.com/en/docs/warnings/v3054
V3025https://pvs-studio.com/en/docs/warnings/v3025/
V3002https://pvs-studio.com/en/docs/warnings/v3002/
V3095https://pvs-studio.com/en/docs/warnings/v3095/
V3095https://pvs-studio.com/en/docs/warnings/v3095/
V3095https://pvs-studio.com/en/docs/warnings/v3095/
V3004https://pvs-studio.com/en/docs/warnings/v3004/
V3123https://pvs-studio.com/en/docs/warnings/v3123/
V3121https://pvs-studio.com/en/docs/warnings/v3121/
Issue-Code Cleanupthe issue is for cleaning up the code with no impact on functionalityhttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Issue-Code%20Cleanup%22
Needs-TriageThe issue is new and needs to be triaged by a work group.https://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Needs-Triage%22
Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorshttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Up-for-Grabs%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.