This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Remove [Out] by-value string parameter usage from System.Management. #34091
Merged
jkoritzinsky
merged 7 commits into
dotnet:master
from
jkoritzinsky:No-out-byvalue-string
Dec 19, 2018
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7784a7a
Remove [Out] by-value string parameter usage from System.Management.
jkoritzinsky 4535e5e
Use char[] instead of StringBuilder.
jkoritzinsky 8556bb0
Add SizeParamIndex
jkoritzinsky 6ebe241
PR Feedback.
jkoritzinsky fd8d34d
Remove -1s
jkoritzinsky e38535b
Remove double semicolon
jkoritzinsky 848b5e3
Fix copy-paste error
jkoritzinsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
using System.Globalization; | ||
using System.Reflection; | ||
using System.ComponentModel.Design.Serialization; | ||
using System.Text; | ||
|
||
namespace System.Management | ||
{ | ||
|
@@ -321,8 +322,9 @@ private static string GetWbemPath(IWbemPath wbemPath) | |
|
||
if (status >= 0 && 0 < bufLen) | ||
{ | ||
pathStr = new string ('0', (int) bufLen-1); | ||
status = wbemPath.GetText_(flags, ref bufLen, pathStr); | ||
char[] pathChars = new char[(int)bufLen]; | ||
status = wbemPath.GetText_(flags, ref bufLen, pathChars); | ||
pathStr = new string(pathChars, 0, Array.IndexOf(pathChars, '\0')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is functionally the same as what was being done previously with StringBuilder, in that StringBuilder marshaling will search for the '\0' and use that when copying back the data. We could make this more efficient presumably by using |
||
} | ||
} | ||
|
||
|
@@ -508,11 +510,12 @@ public string RelativePath | |
|
||
if (status >= 0 && 0 < bufLen) | ||
{ | ||
pathStr = new string ('0', (int) bufLen-1); | ||
char[] pathChars = new char[(int)bufLen]; | ||
status = wmiPath.GetText_( | ||
(int) tag_WBEM_GET_TEXT_FLAGS.WBEMPATH_GET_RELATIVE_ONLY, | ||
ref bufLen, | ||
pathStr); | ||
pathChars); | ||
pathStr = new string(pathChars, 0, Array.IndexOf(pathChars, '\0')); | ||
} | ||
|
||
if (status < 0) | ||
|
@@ -607,8 +610,9 @@ public string Server | |
|
||
if (status >= 0 && 0 < uLen) | ||
{ | ||
pathStr = new string ('0', (int) uLen-1); | ||
status = wmiPath.GetServer_(ref uLen, pathStr); | ||
char[] pathChars = new char[(int)uLen]; | ||
status = wmiPath.GetServer_(ref uLen, pathChars); | ||
pathStr = new string(pathChars, 0, Array.IndexOf(pathChars, '\0')); | ||
} | ||
|
||
if (status < 0) | ||
|
@@ -706,11 +710,11 @@ internal string SetNamespacePath(string nsPath, out bool bChange) | |
|
||
if (status >= 0) | ||
{ | ||
string nSpace = new string('0', (int) uLen-1); | ||
status = wmiPathTmp.GetNamespaceAt_(i, ref uLen, nSpace); | ||
char[] space = new char[(int)uLen]; | ||
status = wmiPathTmp.GetNamespaceAt_(i, ref uLen, space); | ||
if (status >= 0) | ||
{ | ||
status = wmiPath.SetNamespaceAt_(i, nSpace); | ||
status = wmiPath.SetNamespaceAt_(i, space); | ||
|
||
if (status < 0) | ||
break; | ||
|
@@ -738,8 +742,9 @@ internal string SetNamespacePath(string nsPath, out bool bChange) | |
|
||
if (status >= 0 && uLen > 0) | ||
{ | ||
string serverNew = new string ('0', (int) uLen-1); | ||
status = wmiPathTmp.GetServer_(ref uLen, serverNew); | ||
char[] newServerChars = new char[(int)uLen]; | ||
status = wmiPathTmp.GetServer_(ref uLen, newServerChars); | ||
string serverNew = new string(newServerChars, 0, Array.IndexOf(newServerChars, '\0')); | ||
|
||
if (status >= 0) | ||
{ | ||
|
@@ -750,8 +755,9 @@ internal string SetNamespacePath(string nsPath, out bool bChange) | |
|
||
if (status >= 0) | ||
{ | ||
string serverOrg = new string('0', (int)uLen-1); | ||
status = wmiPath.GetServer_(ref uLen, serverOrg); | ||
char[] orgServerChars = new char[(int)uLen]; | ||
status = wmiPath.GetServer_(ref uLen, orgServerChars); | ||
string serverOrg = new string(orgServerChars, 0, Array.IndexOf(orgServerChars, '\0')); | ||
|
||
if (status >= 0 && !string.Equals(serverOrg, serverNew, StringComparison.OrdinalIgnoreCase)) | ||
status = wmiPath.SetServer_(serverNew); | ||
|
@@ -808,8 +814,9 @@ internal static string GetNamespacePath(IWbemPath wbemPath, int flags) | |
|
||
if (status >= 0 && bufLen > 0) | ||
{ | ||
pathStr = new string ('0', (int) bufLen-1); | ||
status = wbemPath.GetText_(flags, ref bufLen, pathStr); | ||
char[] pathChars = new char[(int)bufLen]; | ||
status = wbemPath.GetText_(flags, ref bufLen, pathChars); | ||
pathStr = new string(pathChars, 0, Array.IndexOf(pathChars, '\0')); | ||
} | ||
} | ||
|
||
|
@@ -905,8 +912,9 @@ internal string internalClassName | |
|
||
if (status >= 0 && 0 < bufLen) | ||
{ | ||
pathStr = new string ('0', (int) bufLen-1); | ||
status = wmiPath.GetClassName_(ref bufLen, pathStr); | ||
char[] pathChars = new char[(int)bufLen]; | ||
status = wmiPath.GetClassName_(ref bufLen, pathChars); | ||
pathStr = new string(pathChars, 0, Array.IndexOf(pathChars, '\0')); | ||
|
||
if (status < 0) | ||
pathStr = string.Empty; | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this MarshalAs necessary? What impact does it have on behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
MarshalAs
makes it explicit that we're using Unicode characters. Without it, it was marshalling the array as an ANSI array.