Skip to content

Commit

Permalink
Merge pull request #35 from TsFreddie/string-fix
Browse files Browse the repository at this point in the history
Resize string buffer to account for bytes instead of chars
  • Loading branch information
FirstGearGames authored May 1, 2022
2 parents c291e63 + e26cd76 commit 0198aa5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Assets/FishNet/Runtime/Serializing/Writer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,10 @@ public void WriteString(string value)
* never intentionally inflict allocations on itself.
* Reader ensures string count cannot exceed received
* packet size. */
if (value.Length >= _stringBuffer.Length)
int valueMaxBytes = _encoding.GetMaxByteCount(value.Length);
if (valueMaxBytes >= _stringBuffer.Length)
{
int nextSize = (_stringBuffer.Length * 2) + value.Length;
int nextSize = (_stringBuffer.Length * 2) + valueMaxBytes;
Array.Resize(ref _stringBuffer, nextSize);
}

Expand Down

0 comments on commit 0198aa5

Please sign in to comment.