[Lua] Avoid infinite loop when creating empty string (#6614)

* [Lua] Avoid infinite loop when creating empty string

* [Lua] Check empty string output
This commit is contained in:
罗泽轩
2021-05-06 10:39:42 +08:00
committed by GitHub
parent 82aed82b84
commit a4bb8f0c2e
2 changed files with 20 additions and 1 deletions

View File

@@ -222,6 +222,18 @@ local function testCanonicalData()
checkReadBuffer(wireData)
end
local function testCreateEmptyString()
local b = flatbuffers.Builder(0)
local str = b:CreateString("")
monster.Start(b)
monster.AddName(b, str)
b:Finish(monster.End(b))
local s = b:Output()
local data = flatbuffers.binaryArray.New(s)
local mon = monster.GetRootAsMonster(data, 0)
assert(mon:Name() == "")
end
local function benchmarkMakeMonster(count, reuseBuilder)
local fbb = reuseBuilder and flatbuffers.Builder(0)
local length = #(generateMonster(false, fbb))
@@ -285,6 +297,10 @@ local tests =
f = testCanonicalData,
d = "Tests Canonical flatbuffer file included in repo"
},
{
f = testCreateEmptyString,
d = "Avoid infinite loop when creating empty string"
},
{
f = getRootAs_canAcceptString,
d = "Tests that GetRootAs<type>() generated methods accept strings"