-
Notifications
You must be signed in to change notification settings - Fork 1.4k
CA1838 Avoid 'StringBuilder' parameters for P/Invokes #7186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
994b696
CA1838 Avoid 'StringBuilder' parameters for P/Invokes
elachlan 4b519a9
revert ruleset change
elachlan 3a88ed9
rebase
elachlan 638775f
Enable warning on CA1838
elachlan 751fea3
Merge branch 'main' into CA1838
elachlan 661c2c8
CA1838 Avoid 'StringBuilder' parameters for P/Invokes. Consider using…
elachlan 4f0424c
trying again
elachlan e042e66
Changes from review
elachlan 4ddf661
GetGacPath changes
elachlan 8f0c31c
Making sure we are form strings properly
elachlan 04e4a1b
changes from review
elachlan 903f35d
Remove unused field
elachlan 69cf05f
Use ArrayPool in GetRuntimeVersion and fix usage in GetModuleFileName
elachlan 300179b
Refactor GetRuntimeVersion to remove loop and use stackalloc
elachlan c392277
changes from review
elachlan de3618c
Fix conflict and xml doc
elachlan a0178d7
Merge branch 'main' into CA1838
elachlan 54878ac
Fix possible StackOverflow in GetShortPathName/GetLongPathName by mov…
elachlan 567cc08
Merge branch 'CA1838' of github.com:elachlan/msbuild into CA1838
elachlan 8af24e5
remove unneeded unsafe from pinvoke definitions
elachlan 031af51
Added cached GAC Path and changes from review
elachlan b4f6bf7
Add documentation to Pinvoke
elachlan b5f60db
Changes from review
elachlan 53d3da4
Change from review
elachlan 0a97bfd
Add VerifyThrow instead of loop condition
elachlan 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 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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -567,7 +567,7 @@ internal static string GetRuntimeVersion(string path) | |
| #if FEATURE_MSCOREE | ||
| if (NativeMethodsShared.IsWindows) | ||
| { | ||
| StringBuilder runtimeVersion; | ||
| char[] runtimeVersion; | ||
| uint hresult; | ||
| #if DEBUG | ||
| // Just to make sure and exercise the code that doubles the size | ||
|
|
@@ -578,18 +578,19 @@ internal static string GetRuntimeVersion(string path) | |
| #endif | ||
| do | ||
| { | ||
| runtimeVersion = new StringBuilder(bufferLength); | ||
| runtimeVersion = new char[bufferLength]; | ||
elachlan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| hresult = NativeMethods.GetFileVersion(path, runtimeVersion, bufferLength, out _); | ||
|
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. That said, I'm not a fan of this code, so I'm glad it's gone 😁 |
||
| bufferLength *= 2; | ||
| } while (hresult == NativeMethodsShared.ERROR_INSUFFICIENT_BUFFER); | ||
| } | ||
| while (hresult == NativeMethodsShared.ERROR_INSUFFICIENT_BUFFER); | ||
|
|
||
| if (hresult == NativeMethodsShared.S_OK) | ||
| { | ||
| return runtimeVersion.ToString(); | ||
| return new string(runtimeVersion); | ||
elachlan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| else | ||
| { | ||
| return String.Empty; | ||
| return string.Empty; | ||
| } | ||
| } | ||
| else | ||
|
|
||
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
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.