Skip to content

Commit 39deb1c

Browse files
committed
Fix CA2020: Prevent behavioral change caused by built-in operators of IntPtr/UIntPtr
https://learn.microsoft.com/en-gb/dotnet/fundamentals/code-analysis/quality-rules/ca2020
1 parent a993992 commit 39deb1c

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

.globalconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,10 @@ dotnet_diagnostic.CA2015.severity = warning
558558
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2016
559559
dotnet_diagnostic.CA2016.severity = suggestion
560560

561+
# CA2020: Prevent behavioral change caused by built-in operators of IntPtr/UIntPtr
562+
# https://learn.microsoft.com/en-gb/dotnet/fundamentals/code-analysis/quality-rules/ca2020
563+
dotnet_diagnostic.CA2020.severity = warning
564+
561565
# CA2100: Review SQL queries for security vulnerabilities
562566
# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2100
563567
dotnet_diagnostic.CA2100.severity = none

src/System.Management.Automation/engine/remoting/fanin/WSManNativeAPI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ internal WSManOptionSet(WSManOption[] options)
11211121
// Look at the structure of native WSManOptionSet.. Options is a pointer..
11221122
// In C-Style array individual elements are continuous..so I am building
11231123
// continuous array elements here.
1124-
Marshal.StructureToPtr(options[index], (IntPtr)(_optionSet.options.ToInt64() + (sizeOfOption * index)), false);
1124+
Marshal.StructureToPtr(options[index], _optionSet.options + (sizeOfOption * index), false);
11251125
}
11261126

11271127
_data = MarshalledObject.Create<WSManOptionSetStruct>(_optionSet);

src/powershell/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ private static void AttemptExecPwshLogin(string[] args)
116116
// Read the symlink to the startup executable
117117
IntPtr linkPathPtr = Marshal.AllocHGlobal(LINUX_PATH_MAX);
118118
IntPtr bufSize = ReadLink("/proc/self/exe", linkPathPtr, (UIntPtr)LINUX_PATH_MAX);
119-
pwshPath = Marshal.PtrToStringAnsi(linkPathPtr, (int)bufSize);
119+
pwshPath = Marshal.PtrToStringAnsi(linkPathPtr, checked((int)bufSize));
120120
Marshal.FreeHGlobal(linkPathPtr);
121121

122122
ArgumentNullException.ThrowIfNull(pwshPath);

0 commit comments

Comments
 (0)