[Mono-bugs] [Bug 76155][Blo] New - BinaryWriter writes bytes on integers in wrong order on Darwin.

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Mon Sep 19 20:56:44 EDT 2005


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by nev at delap.com.

http://bugzilla.ximian.com/show_bug.cgi?id=76155

--- shadow/76155	2005-09-19 20:56:44.000000000 -0400
+++ shadow/76155.tmp.13629	2005-09-19 20:56:44.000000000 -0400
@@ -0,0 +1,77 @@
+Bug#: 76155
+Product: Mono: Class Libraries
+Version: 1.1
+OS: other
+OS Details: Mac OS X 10.4.2. Darwin.
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Blocker
+Component: System
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: Nev at Delap.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: BinaryWriter writes bytes on integers in wrong order on Darwin.
+
+This test...
+
+  1) checks that the bytes in an integer containing 1 are in the order 
+that they should be, little endian on windows and linux on x86, and big 
+endian on Mac OS 10.4.2.
+  2) writes the 1 into a stream, first by just writing the 1, and second 
+by converting it to NetworkOrder and writing it.
+
+On Windows and linux the results are what I'd expect... bytes containing 
+1, 0, 0, 0, 0, 0, 0, 1 (a little endian 1 and a big endian 1).
+
+On Darwin the results are not what I'd expect... bytes containing 1, 0, 
+0, 0, 1, 0, 0, 0 (two little endian 1's). I would have expected two big 
+endian 1's, since otherwise I'd have to convert the big endian integer 
+into not network order in order to get it on the wire in network order on 
+the Mac.
+
+So I think Darwin's HostToNetworkOrder is working but the stream reverses 
+the bytes when it shouldn't.
+
+[Test]
+public void HostToNetworkOrderInStreams()
+{
+    int one = 1;
+    unsafe
+    {
+        byte* onep = (byte*)&one;
+#if Linux || Windows || !CommandLine
+        Assert.AreEqual(1, onep[0]);
+        Assert.AreEqual(0, onep[1]);
+        Assert.AreEqual(0, onep[2]);
+        Assert.AreEqual(0, onep[3]);
+#elif Darwin
+        Assert.AreEqual(0, onep[0]);
+        Assert.AreEqual(0, onep[1]);
+        Assert.AreEqual(0, onep[2]);
+        Assert.AreEqual(1, onep[3]);
+#else
+        Assert.Fail("You're running a platform not tested here.");
+#endif
+    }
+    byte[] bytes = new byte[16];
+    MemoryStream memoryStream = new MemoryStream(bytes);
+    BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
+    binaryWriter.Write(one);
+    binaryWriter.Write(IPAddress.HostToNetworkOrder(one));
+    for (int i = 0; i < 8; i++)
+    {
+        Console.Write("{0} ", bytes[i]);
+    }
+    Assert.AreEqual(bytes[0],  1, "0");
+    Assert.AreEqual(bytes[1],  0, "1");
+    Assert.AreEqual(bytes[2],  0, "2");
+    Assert.AreEqual(bytes[3],  0, "3");
+    Assert.AreEqual(bytes[4],  0, "4"); << Darwin fails here.
+    Assert.AreEqual(bytes[5],  0, "5");
+    Assert.AreEqual(bytes[6],  0, "6");
+    Assert.AreEqual(bytes[7],  1, "7");
+}


More information about the mono-bugs mailing list