Skip to content

Commit

Permalink
disallow malformed ffi.typeof inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
q66 committed Nov 1, 2022
1 parent 559c978 commit d762282
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2677,7 +2677,7 @@ ast::c_type parse_type(
{
lex_state ls{L, input, iend, PARSE_MODE_NOTCDEF, paridx};
ast::c_type tp{};
if (!ls.get() || !parse_type(ls, tp)) {
if (!ls.get() || !parse_type(ls, tp) || !check(ls, -1)) {
if (ls.err_token() > 0) {
char buf[16];
lua_pushfstring(
Expand Down
9 changes: 9 additions & 0 deletions tests/istype.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,12 @@ assert(not ffi.istype("int &", ffi.typeof("float &")))
-- second argument must be a cval
assert(not ffi.istype("int", "int"))
assert(not ffi.istype("int", true))

-- types in typeof must be terminated
local ret, msg = pcall(ffi.typeof, "long int bla")
assert(not ret)
assert(msg == "'<eof>' expected near '<name>'")

local ret, msg = pcall(ffi.typeof, "long int int")
assert(not ret)
assert(msg == "'<eof>' expected near 'int'")

0 comments on commit d762282

Please sign in to comment.