Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCalvin Buckley <calvin@cmpct.info>2019-11-25 21:15:55 +0300
committermonojenkins <jo.shields+jenkins@xamarin.com>2019-11-25 21:15:55 +0300
commit836f45390628c0d05b45d7b27237634062b224a8 (patch)
tree97da5000702fb9dd30d351243d0a933439c055e0 /mcs/class/referencesource
parentbdf4790fa061704a6e40d55c07b214961e5083cc (diff)
Fix BinaryReader on BE (#17893)
Fix BinaryReader on BE The ints passed into the int array ctor needed to be endian swapped. Interestingly, the BinaryWriter implementation currently being used (not refsrc AFAIK) does this on write just fine. Fixes ReadDecimal test on AIX, and adds another test to ensure that Write(decimal) can be read back by ReadDecimal in case.
Diffstat (limited to 'mcs/class/referencesource')
-rw-r--r--mcs/class/referencesource/mscorlib/system/io/binaryreader.cs7
1 files changed, 7 insertions, 0 deletions
diff --git a/mcs/class/referencesource/mscorlib/system/io/binaryreader.cs b/mcs/class/referencesource/mscorlib/system/io/binaryreader.cs
index e4e1ecfe376..9f1b89de5d5 100644
--- a/mcs/class/referencesource/mscorlib/system/io/binaryreader.cs
+++ b/mcs/class/referencesource/mscorlib/system/io/binaryreader.cs
@@ -23,6 +23,7 @@ namespace System.IO {
using System.Globalization;
using System.Diagnostics.Contracts;
using System.Security;
+ using System.Buffers.Binary;
[System.Runtime.InteropServices.ComVisible(true)]
public class BinaryReader : IDisposable
@@ -243,6 +244,12 @@ namespace System.IO {
try {
int[] ints = new int[4];
Buffer.BlockCopy(m_buffer, 0, ints, 0, 16);
+ if (!BitConverter.IsLittleEndian) {
+ // We need to reverse the ints on BE
+ for (int i = 0; i < 4; i++) {
+ ints[i] = BinaryPrimitives.ReverseEndianness(ints[i]);
+ }
+ }
return new decimal(ints);
}
catch (ArgumentException e) {