mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-29 04:30:00 +00:00
fix using null string in vector (#7872)
Use 0 offset as special value. 0 offset is not a valid relative offset, so it's safe to use 0 offset to indicate value is null. https://github.com/google/flatbuffers/issues/7846
This commit is contained in:
@@ -438,7 +438,8 @@ namespace Google.FlatBuffers
|
|||||||
if (off > Offset)
|
if (off > Offset)
|
||||||
throw new ArgumentException();
|
throw new ArgumentException();
|
||||||
|
|
||||||
off = Offset - off + sizeof(int);
|
if (off != 0)
|
||||||
|
off = Offset - off + sizeof(int);
|
||||||
PutInt(off);
|
PutInt(off);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,11 @@ namespace Google.FlatBuffers
|
|||||||
// Create a .NET String from UTF-8 data stored inside the flatbuffer.
|
// Create a .NET String from UTF-8 data stored inside the flatbuffer.
|
||||||
public string __string(int offset)
|
public string __string(int offset)
|
||||||
{
|
{
|
||||||
offset += bb.GetInt(offset);
|
int stringOffset = bb.GetInt(offset);
|
||||||
|
if (stringOffset == 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
offset += stringOffset;
|
||||||
var len = bb.GetInt(offset);
|
var len = bb.GetInt(offset);
|
||||||
var startPos = offset + sizeof(int);
|
var startPos = offset + sizeof(int);
|
||||||
return bb.GetStringUTF8(startPos, len);
|
return bb.GetStringUTF8(startPos, len);
|
||||||
|
|||||||
Reference in New Issue
Block a user