Skip to content

Commit

Permalink
Merge pull request #31 from zsebastian/master
Browse files Browse the repository at this point in the history
Fixed sublte bug in ReadUInt64(int) and PeekUInt64(int)
  • Loading branch information
lidgren committed Aug 4, 2015
2 parents 2a0027e + f17202f commit e9d0c08
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Lidgren.Network/NetBuffer.Peek.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public UInt64 PeekUInt64(int numberOfBits)
else
{
retval = NetBitWriter.ReadUInt32(m_data, 32, m_readPosition);
retval |= NetBitWriter.ReadUInt32(m_data, numberOfBits - 32, m_readPosition) << 32;
retval |= (UInt64)NetBitWriter.ReadUInt32(m_data, numberOfBits - 32, m_readPosition + 32) << 32;
}
return retval;
}
Expand Down
2 changes: 1 addition & 1 deletion Lidgren.Network/NetBuffer.Read.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public UInt64 ReadUInt64(int numberOfBits)
else
{
retval = NetBitWriter.ReadUInt32(m_data, 32, m_readPosition);
retval |= NetBitWriter.ReadUInt32(m_data, numberOfBits - 32, m_readPosition) << 32;
retval |= (UInt64)NetBitWriter.ReadUInt32(m_data, numberOfBits - 32, m_readPosition + 32) << 32;
}
m_readPosition += numberOfBits;
return retval;
Expand Down
10 changes: 8 additions & 2 deletions UnitTests/ReadWriteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static void Run(NetPeer peer)
msg.Write("duke of earl");
msg.Write((byte)43);
msg.Write((ushort)44);
msg.Write(UInt64.MaxValue, 64);
msg.Write(true);

msg.WritePadBits();
Expand Down Expand Up @@ -83,8 +84,13 @@ public static void Run(NetPeer peer)
throw new NetException("Read/write failure");

bdr.Append(inc.ReadUInt16());

if (inc.PeekUInt64(64) != UInt64.MaxValue)
throw new NetException("Read/write failure");

bdr.Append(inc.ReadUInt64());
bdr.Append(inc.ReadBoolean());

inc.SkipPadBits();

bdr.Append(inc.ReadSingle());
Expand All @@ -96,7 +102,7 @@ public static void Run(NetPeer peer)
bdr.Append(inc.ReadVariableUInt32());
bdr.Append(inc.ReadVariableInt64());

if (bdr.ToString().Equals("False-342duke of earl4344True56784521159980224614-4747000048-49"))
if (bdr.ToString().Equals("False-342duke of earl434418446744073709551615True56784521159980224614-4747000048-49"))
Console.WriteLine("Read/write tests OK");
else
throw new NetException("Read/write tests FAILED!");
Expand Down

0 comments on commit e9d0c08

Please sign in to comment.