Skip to content

Commit

Permalink
Fix bson reader wrong cache CString buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
mbdavid committed Jan 2, 2018
1 parent 52e117a commit 83f193a
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions LiteDB/Document/Bson/BsonReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,19 @@ private string ReadString(ByteReader reader)
return Encoding.UTF8.GetString(bytes, 0, length - 1);
}

// use byte array buffer for CString (key-only)
private byte[] _strBuffer = new byte[1000];

private string ReadCString(ByteReader reader)
{
var pos = 0;
var buffer = new byte[200];

while (true)
{
byte buf = reader.ReadByte();
if (buf == 0x00) break;
_strBuffer[pos++] = buf;
var data = reader.ReadByte();
if (data == 0x00 || pos == 200) break;
buffer[pos++] = data;
}

return Encoding.UTF8.GetString(_strBuffer, 0, pos);
return Encoding.UTF8.GetString(buffer, 0, pos);
}
}
}

0 comments on commit 83f193a

Please sign in to comment.