MCPcopy Create free account
hub / github.com/9chu/LuaSTGPlus / json_check_encode_depth

Function json_check_encode_depth

LuaSTGPlus/LuaExtensions/cjson4lua/lua_cjson.c:539–560  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

537}
538
539static void json_check_encode_depth(lua_State *l, json_config_t *cfg,
540 int current_depth, strbuf_t *json)
541{
542 /* Ensure there are enough slots free to traverse a table (key,
543 * value) and push a string for a potential error message.
544 *
545 * Unlike "decode", the key and value are still on the stack when
546 * lua_checkstack() is called. Hence an extra slot for luaL_error()
547 * below is required just in case the next check to lua_checkstack()
548 * fails.
549 *
550 * While this won't cause a crash due to the EXTRA_STACK reserve
551 * slots, it would still be an improper use of the API. */
552 if (current_depth <= cfg->encode_max_depth && lua_checkstack(l, 3))
553 return;
554
555 if (!cfg->encode_keep_buffer)
556 strbuf_free(json);
557
558 luaL_error(l, "Cannot serialise, excessive nesting (%d)",
559 current_depth);
560}
561
562static void json_append_data(lua_State *l, json_config_t *cfg,
563 int current_depth, strbuf_t *json);

Callers 1

json_append_dataFunction · 0.85

Calls 1

strbuf_freeFunction · 0.85

Tested by

no test coverage detected