Skip to content
Snippets Groups Projects
Commit f82473f7 authored by Roman Tsisyk's avatar Roman Tsisyk
Browse files

Fix #493: Segmentation fault with isnil

parent 45182c81
No related branches found
No related tags found
No related merge requests found
......@@ -36,6 +36,9 @@ local UUID_LEN = ffi.sizeof(uuid_t)
local uuidbuf = ffi.new(uuid_t)
local uuid_tostring = function(uu)
if not ffi.istype(uuid_t, uu) then
return error('Usage: uuid:str()')
end
return ffi.string(builtin.tt_uuid_str(uu), UUID_STR_LEN)
end
......@@ -62,6 +65,9 @@ local need_bswap = function(order)
end
local uuid_tobin = function(uu, byteorder)
if not ffi.istype(uuid_t, uu) then
return error('Usage: uuid:bin([byteorder])')
end
if need_bswap(byteorder) then
if uu ~= uuidbuf then
ffi.copy(uuidbuf, uu, UUID_LEN)
......@@ -85,6 +91,9 @@ local uuid_frombin = function(bin, byteorder)
end
local uuid_isnil = function(uu)
if not ffi.istype(uuid_t, uu) then
return error('Usage: uuid:isnil()')
end
return builtin.tt_uuid_is_nil(uu)
end
......@@ -92,6 +101,9 @@ local uuid_eq = function(lhs, rhs)
if not ffi.istype(uuid_t, rhs) then
return false
end
if not ffi.istype(uuid_t, lhs) then
return error('Usage: uuid == var')
end
return builtin.tt_uuid_is_equal(lhs, rhs)
end
......
......@@ -106,7 +106,7 @@ uu.node[5]
-- invalid values
uuid.fromstr(nil)
---
- error: 'builtin/uuid.lua:44: fromstr(str)'
- error: 'builtin/uuid.lua:47: fromstr(str)'
...
uuid.fromstr('')
---
......@@ -244,6 +244,27 @@ uu == "blablabla"
---
- false
...
--
-- invalid usage
--
uu = uuid.new()
---
...
uu.isnil()
---
- error: 'Usage: uuid:isnil()'
...
uu.bin()
---
- error: 'Usage: uuid:bin([byteorder])'
...
uu.str()
---
- error: 'Usage: uuid:str()'
...
uu = nil
---
...
uuid = nil
---
...
......@@ -85,4 +85,14 @@ uu == nil
uu == 12345
uu == "blablabla"
--
-- invalid usage
--
uu = uuid.new()
uu.isnil()
uu.bin()
uu.str()
uu = nil
uuid = nil
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment