Fix overflow exception in Microsoft.Diagnostics.Monitoring (#3400)
authorMike McLaughlin <mikem@microsoft.com>
Tue, 20 Sep 2022 22:25:21 +0000 (15:25 -0700)
committerGitHub <noreply@github.com>
Tue, 20 Sep 2022 22:25:21 +0000 (15:25 -0700)
Issue: https://github.com/dotnet/diagnostics/issues/3392

src/Tools/dotnet-gcdump/DotNetHeapDump/Graph.cs

index e9f61ce2d1650587f492279ed80a075cad4b2cee..7280bbdb3f21e1c92390cc99a9b13e4af7001e6c 100644 (file)
@@ -882,35 +882,38 @@ namespace Graphs
 
         internal static void WriteCompressedInt(SegmentedMemoryStreamWriter writer, int value)
         {
-            if (value << 25 >> 25 == value)
+            unchecked
             {
-                goto oneByte;
-            }
+                if (value << 25 >> 25 == value)
+                {
+                    goto oneByte;
+                }
 
-            if (value << 18 >> 18 == value)
-            {
-                goto twoBytes;
-            }
+                if (value << 18 >> 18 == value)
+                {
+                    goto twoBytes;
+                }
 
-            if (value << 11 >> 11 == value)
-            {
-                goto threeBytes;
-            }
+                if (value << 11 >> 11 == value)
+                {
+                    goto threeBytes;
+                }
 
-            if (value << 4 >> 4 == value)
-            {
-                goto fourBytes;
-            }
+                if (value << 4 >> 4 == value)
+                {
+                    goto fourBytes;
+                }
 
-            writer.Write((byte)((value >> 28) | 0x80));
+                writer.Write((byte)((value >> 28) | 0x80));
             fourBytes:
-            writer.Write((byte)((value >> 21) | 0x80));
+                writer.Write((byte)((value >> 21) | 0x80));
             threeBytes:
-            writer.Write((byte)((value >> 14) | 0x80));
+                writer.Write((byte)((value >> 14) | 0x80));
             twoBytes:
-            writer.Write((byte)((value >> 7) | 0x80));
+                writer.Write((byte)((value >> 7) | 0x80));
             oneByte:
-            writer.Write((byte)(value & 0x7F));
+                writer.Write((byte)(value & 0x7F));
+            }
         }
 
         internal NodeIndex m_index;