From e817e4de28838fae205f1de6f41c427ba0f60fe6 Mon Sep 17 00:00:00 2001 From: Robin Wellner Date: Sun, 4 Nov 2018 13:07:19 +0000 Subject: [PATCH] Close #12 (serialization bug for string "len") Thanks to nikki93 for spotting the issue and suggesting this solution. --- bitser.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bitser.lua b/bitser.lua index 7fa350b..ee08f18 100644 --- a/bitser.lua +++ b/bitser.lua @@ -27,6 +27,7 @@ local buf_size = -1 local buf = nil local writable_buf = nil local writable_buf_size = nil +local SEEN_LEN = {} local function Buffer_prereserve(min_size) if buf_size < min_size then @@ -222,8 +223,8 @@ serialize_value = function(value, seen) end local t = type(value) if t ~= 'number' and t ~= 'boolean' and t ~= 'nil' then - seen[value] = seen.len - seen.len = seen.len + 1 + seen[value] = seen[SEEN_LEN] + seen[SEEN_LEN] = seen[SEEN_LEN] + 1 end if resource_name_registry[value] then local name = resource_name_registry[value] @@ -245,7 +246,7 @@ end local function serialize(value) Buffer_makeBuffer(4096) - local seen = {len = 0} + local seen = {[SEEN_LEN] = 0} serialize_value(value, seen) end