Fix invalid IntPtr == null comparisons, set strict mode for Roslyn (#19191)
authorJacek Blaszczynski <biosciencenow@outlook.com>
Mon, 30 Jul 2018 00:56:32 +0000 (02:56 +0200)
committerJan Kotas <jkotas@microsoft.com>
Mon, 30 Jul 2018 00:56:32 +0000 (17:56 -0700)
Issue reported in https://github.com/dotnet/corefx/issues/31456
Solution is to compare always against IntPtr.Zero and use Roslyn
stric mode for reporting warnings for IntPtr == null comparisons

Directory.Build.props
src/System.Private.CoreLib/src/System/StubHelpers.cs

index 3efd9a3..2082362 100644 (file)
@@ -2,4 +2,8 @@
   <PropertyGroup>
     <CL_MPCount>$(NumberOfCores)</CL_MPCount>
   </PropertyGroup>
+  <PropertyGroup>
+    <!-- Enables Strict mode for Roslyn compiler -->
+    <Features>strict</Features>
+  </PropertyGroup>
 </Project>
index 6d9e7a8..b8e34e0 100644 (file)
@@ -200,7 +200,7 @@ namespace System.StubHelpers
 
         internal static unsafe void ConvertToManaged(StringBuilder sb, IntPtr pNative)
         {
-            if (pNative == null)
+            if (pNative == IntPtr.Zero)
                 return;
 
             int nbBytes = StubHelpers.strlen((sbyte*)pNative);