Skip to content

Commit 8fcdde2

Browse files
committed
[fix] 清空空白部分,避免出现脏数据
1 parent 9441d9c commit 8fcdde2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

NewLife.Core/Serialization/Binary/Binary.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,15 @@ public void WriteBCD(String value, Int32 max)
512512
/// <param name="max"></param>
513513
public void WriteFixedString(String? value, Int32 max)
514514
{
515+
var len = 0;
515516
var buf = Pool.Shared.Rent(max);
516-
if (!value.IsNullOrEmpty()) Encoding.GetBytes(value, 0, value.Length, buf, 0);
517+
if (!value.IsNullOrEmpty()) len = Encoding.GetBytes(value, 0, value.Length, buf, 0);
518+
519+
// 清空空白部分,避免出现脏数据
520+
if (len < max) Array.Clear(buf, len, max - len);
517521

518522
Write(buf, 0, max);
523+
519524
Pool.Shared.Return(buf);
520525
}
521526

0 commit comments

Comments
 (0)