aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lua_cjson.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/lua_cjson.c b/lua_cjson.c
index fea3ed5..f5af350 100644
--- a/lua_cjson.c
+++ b/lua_cjson.c
@@ -532,10 +532,17 @@ static int lua_array_length(lua_State *l, json_config_t *cfg, strbuf_t *json)
532static void json_check_encode_depth(lua_State *l, json_config_t *cfg, 532static void json_check_encode_depth(lua_State *l, json_config_t *cfg,
533 int current_depth, strbuf_t *json) 533 int current_depth, strbuf_t *json)
534{ 534{
535 /* Ensure there are enough slots free to traverse a table (key, value). 535 /* Ensure there are enough slots free to traverse a table (key,
536 * luaL_error() and other Lua API functions use space from the 536 * value) and push a string for a potential error message.
537 * "EXTRA_STACK" reserve. */ 537 *
538 if (current_depth <= cfg->encode_max_depth && lua_checkstack(l, 2)) 538 * Unlike "decode", the key and value are still on the stack when
539 * lua_checkstack() is called. Hence an extra slot for luaL_error()
540 * below is required just in case the next check to lua_checkstack()
541 * fails.
542 *
543 * While this won't cause a crash due to the EXTRA_STACK reserve
544 * slots, it would still be an improper use of the API. */
545 if (current_depth <= cfg->encode_max_depth && lua_checkstack(l, 3))
539 return; 546 return;
540 547
541 if (!cfg->encode_keep_buffer) 548 if (!cfg->encode_keep_buffer)