Skip to content

Commit

Permalink
Packet的Next不为Null的情况下,Set方法中的递归调用,存在bug。 (NewLifeX#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccliushou authored Jun 8, 2022
1 parent 9db447d commit 2bf0436
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions NewLife.Core/Data/Packet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ public Byte this[Int32 index]

Next[p - Data.Length] = value;
}

Data[p] = value;
if(p < Count)
Data[p] = value;

// 基础类需要严谨给出明确功用,不能模棱两可,因此不能越界
}
}
Expand Down
12 changes: 12 additions & 0 deletions XUnitTest.Core/Data/PacketTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,18 @@ public void AppendTest()
Assert.Equal("StoneNewLife", pk.ToStr());
}

[Fact]
public void AfterAppendSetTest()
{
var buf = "Stone".GetBytes();

var pk = new Packet(buf);
pk.Append("11111".GetBytes());
pk.Append("22222".GetBytes());
pk[12] = 0x11;
Assert.NotNull(pk.Next);
Assert.Equal(pk[12],(byte)0x11);
}
[Fact]
public void NextTest()
{
Expand Down

0 comments on commit 2bf0436

Please sign in to comment.