From 5a134b4fce32de2ef0f6b4771b74a750903b9e16 Mon Sep 17 00:00:00 2001 From: "R.E.J. Wellner" Date: Mon, 27 Apr 2020 19:47:09 +0200 Subject: [PATCH] Close #13 Turns out I never fixed this one bug... --- bitser.lua | 6 ++++++ conf.lua | 2 +- main.lua | 8 ++++---- spec/bitser_spec.lua | 6 ++++++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/bitser.lua b/bitser.lua index 43399ac..47984d5 100644 --- a/bitser.lua +++ b/bitser.lua @@ -375,9 +375,15 @@ end, loadLoveFile = function(fname) -- so make sure deserialize_value returns before loadLoveFile does return value end, loadData = function(data, size) + if size == 0 then + error('cannot load value from empty data') + end Buffer_newDataReader(data, size) return deserialize_value({}) end, loads = function(str) + if #str == 0 then + error('cannot load value from empty string') + end Buffer_newReader(str) return deserialize_value({}) end, register = function(name, resource) diff --git a/conf.lua b/conf.lua index 9b1f427..ebf29ea 100644 --- a/conf.lua +++ b/conf.lua @@ -1,4 +1,4 @@ function love.conf(t) - t.version = "0.10.0" + t.version = "11.3" t.console = true end \ No newline at end of file diff --git a/main.lua b/main.lua index 2c5a35d..94f1a4f 100644 --- a/main.lua +++ b/main.lua @@ -48,8 +48,8 @@ local resultname = "serialisation time in seconds" function love.load() cases = love.filesystem.getDirectoryItems("cases") state = 'select_case' - love.graphics.setBackgroundColor(255, 230, 220) - love.graphics.setColor(40, 30, 0) + love.graphics.setBackgroundColor(1, 230/256, 220/256) + love.graphics.setColor(40/256, 30/256, 0/256) love.window.setTitle("Select a benchmark testcase") end @@ -168,9 +168,9 @@ function love.draw() for sername, result in pairs(results) do love.graphics.print(sername, 20, i * 20) if result == math.huge then - love.graphics.setColor(220, 30, 0) + love.graphics.setColor(220/256, 30/256, 0) love.graphics.rectangle('fill', 100, i * 20, 780 - 100, 18) - love.graphics.setColor(40, 30, 0) + love.graphics.setColor(40/256, 30/256, 0) else love.graphics.rectangle('fill', 100, i * 20, (780 - 100) * (result - results_min) / (results_max - results_min), 18) end diff --git a/spec/bitser_spec.lua b/spec/bitser_spec.lua index e3d91e4..b12d2a2 100644 --- a/spec/bitser_spec.lua +++ b/spec/bitser_spec.lua @@ -279,6 +279,12 @@ describe("bitser", function() it("can load from raw data", function() assert.are.same(bitser.loadData(ffi.new("uint8_t[4]", 195, 103, 118, 120), 4), "gvx") end) + it("will not read from zero length data", function() + assert.has_error(function() bitser.loadData(ffi.new("uint8_t[1]", 0), 0) end) + end) + it("will not read from zero length string", function() + assert.has_error(function() bitser.loads("") end) + end) it("will not read past the end of the buffer", function() assert.has_error(function() bitser.loadData(ffi.new("uint8_t[4]", 196, 103, 118, 120), 4) end) end)