From 0bdf4d229431dfa241e6fd4d63d144d944f99cfe Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Fri, 16 Jun 2017 12:19:18 +0200 Subject: str_unpack: pos is size_t in C so -1 should raise initial position error --- src/lstrlib.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lstrlib.js b/src/lstrlib.js index a4a5289..7c3fac4 100644 --- a/src/lstrlib.js +++ b/src/lstrlib.js @@ -764,7 +764,7 @@ const str_unpack = function(L) { let ld = data.length; let pos = posrelat(lauxlib.luaL_optinteger(L, 3, 1), ld) - 1; let n = 0; /* number of results */ - lauxlib.luaL_argcheck(L, pos <= ld, 3, lua.to_luastring("initial position out of string", true)); + lauxlib.luaL_argcheck(L, pos <= ld && pos >= 0, 3, lua.to_luastring("initial position out of string", true)); while (fmt.off < fmt.s.length) { let details = getdetails(h, pos, fmt); let opt = details.opt; -- cgit v1.2.3-70-g09d2