From b600ba0123b8af27d2d25e7655b311163afaec91 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Fri, 5 May 2017 10:33:23 +1000 Subject: Fix luaL_error callsites - Now that luaL_error does sprintf-like formatting it shouldn't take user input - % now needs to be escaped when passed to luaL_error - Removes several wasteful lua->js->lua string transformations --- src/ltablib.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/ltablib.js') diff --git a/src/ltablib.js b/src/ltablib.js index 56ba2cd..788e236 100644 --- a/src/ltablib.js +++ b/src/ltablib.js @@ -47,7 +47,8 @@ const aux_getn = function(L, n, w) { const addfield = function(L, b, i) { lua.lua_geti(L, 1, i); if (!lua.lua_isstring(L, -1)) - lauxlib.luaL_error(L, lua.to_luastring(`invalid value (${lua.to_jsstring(lauxlib.luaL_typename(L, -1))}) at index ${i} in table for 'concat'`)); + lauxlib.luaL_error(L, lua.to_luastring("invalid value (%s) at index %d in table for 'concat'"), + lauxlib.luaL_typename(L, -1), i); lauxlib.luaL_addvalue(b); }; @@ -206,14 +207,14 @@ const partition = function(L, lo, up) { /* next loop: repeat ++i while a[i] < P */ while (lua.lua_geti(L, 1, ++i), sort_comp(L, -1, -2)) { if (i == up - 1) /* a[i] < P but a[up - 1] == P ?? */ - lauxlib.luaL_error(L, "invalid order function for sorting"); + lauxlib.luaL_error(L, lua.to_luastring("invalid order function for sorting")); lua.lua_pop(L, 1); /* remove a[i] */ } /* after the loop, a[i] >= P and a[lo .. i - 1] < P */ /* next loop: repeat --j while P < a[j] */ while (lua.lua_geti(L, 1, --j), sort_comp(L, -3, -1)) { if (j < i) /* j < i but a[j] > P ?? */ - lauxlib.luaL_error(L, "invalid order function for sorting"); + lauxlib.luaL_error(L, lua.to_luastring("invalid order function for sorting")); lua.lua_pop(L, 1); /* remove a[j] */ } /* after the loop, a[j] <= P and a[j + 1 .. up] >= P */ -- cgit v1.2.3-54-g00ecf