Skip to content

Commit

Permalink
chore: better error descriptions for Val and too long strings
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsci committed Mar 7, 2022
1 parent 4448db6 commit 50e0264
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/fns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,10 @@ function Val(stack, runtime) -- 0x92
local str = stack:pop()
-- printf("Val('%s')\n", hexEscape(str))
local result = tonumber(str)
assert(result, KErrInvalidArgs)
if not result then
printf("Bad Val('%s')\n", hexEscape(str))
error(KErrInvalidArgs)
end
stack:push(result)
end

Expand Down
5 changes: 4 additions & 1 deletion src/memory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,10 @@ function Variable:__call(val)
-- Slow path
local data
if t == EString then
assert(#val <= self:stringMaxLen(), KErrStrTooLong)
if #val > self:stringMaxLen() then
printf("String too long: maxlen=%d val='%s'\n", self:stringMaxLen(), hexEscape(val))
error(KErrStrTooLong)
end
data = string_pack("<B", #val)..val
else
data = string_pack(FmtForType[t], val)
Expand Down

0 comments on commit 50e0264

Please sign in to comment.