Skip to content
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

Fixes for big-endian systems #6204

Merged
merged 1 commit into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Buffers.Binary;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Globalization;
Expand Down Expand Up @@ -738,7 +739,7 @@ public async Task RunPacketReadLoopAsync()
}

NodePacketType packetType = (NodePacketType)_headerByte[0];
int packetLength = BitConverter.ToInt32(_headerByte, 1);
int packetLength = BinaryPrimitives.ReadInt32LittleEndian(new Span<byte>(_headerByte, 1, 4));

_readBufferMemoryStream.SetLength(packetLength);
byte[] packetData = _readBufferMemoryStream.GetBuffer();
Expand Down Expand Up @@ -1027,7 +1028,7 @@ private void HeaderReadComplete(IAsyncResult result)
return;
}

int packetLength = BitConverter.ToInt32(_headerByte, 1);
int packetLength = BinaryPrimitives.ReadInt32LittleEndian(new Span<byte>(_headerByte, 1, 4));
MSBuildEventSource.Log.PacketReadSize(packetLength);

// Ensures the buffer is at least this length.
Expand Down
18 changes: 16 additions & 2 deletions src/Shared/MSBuildNameIgnoreCaseComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,14 @@ public int GetHashCode(string obj, int start, int length)
// the string, and not the null terminator etc.
if (length == 1)
{
val &= 0xFFFF;
if (BitConverter.IsLittleEndian)
{
val &= 0xFFFF;
}
else
{
val &= unchecked((int)0xFFFF0000);
}
}

hash1 = ((hash1 << 5) + hash1 + (hash1 >> 27)) ^ val;
Expand All @@ -162,7 +169,14 @@ public int GetHashCode(string obj, int start, int length)
val = pint[1] & 0x00DF00DF;
if (length == 3)
{
val &= 0xFFFF;
if (BitConverter.IsLittleEndian)
{
val &= 0xFFFF;
}
else
{
val &= unchecked((int)0xFFFF0000);
}
}

hash2 = ((hash2 << 5) + hash2 + (hash2 >> 27)) ^ val;
Expand Down