Skip to content

Commit

Permalink
Fix overflow exception in Microsoft.Diagnostics.Monitoring (#3400)
Browse files Browse the repository at this point in the history
Issue: #3392
  • Loading branch information
mikem8361 authored Sep 20, 2022
1 parent 2569eee commit 8d820d5
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions src/Tools/dotnet-gcdump/DotNetHeapDump/Graph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -882,35 +882,38 @@ internal static int ReadCompressedInt(SegmentedMemoryStreamReader reader)

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;
Expand Down

0 comments on commit 8d820d5

Please sign in to comment.