MCPcopy Create free account
hub / github.com/defold/defold / json_check_encode_depth

Function json_check_encode_depth

engine/script/src/luacjson/lua_cjson.c:715–736  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

713}
714
715static void json_check_encode_depth(lua_State *l, json_config_t *cfg,
716 int current_depth, strbuf_t *json)
717{
718 /* Ensure there are enough slots free to traverse a table (key,
719 * value) and push a string for a potential error message.
720 *
721 * Unlike "decode", the key and value are still on the stack when
722 * lua_checkstack() is called. Hence an extra slot for luaL_error()
723 * below is required just in case the next check to lua_checkstack()
724 * fails.
725 *
726 * While this won't cause a crash due to the EXTRA_STACK reserve
727 * slots, it would still be an improper use of the API. */
728 if (current_depth <= cfg->encode_max_depth && lua_checkstack(l, 3))
729 return;
730
731 // We don't need the buffer if error happened.
732 strbuf_free(json);
733
734 DefoldError(cfg, "Cannot serialise, excessive nesting (%d)",
735 current_depth);
736}
737
738static void json_append_data(lua_State *l, json_config_t *cfg,
739 int current_depth, strbuf_t *json);

Callers 1

json_append_dataFunction · 0.85

Calls 3

lua_checkstackFunction · 0.85
strbuf_freeFunction · 0.85
DefoldErrorFunction · 0.85

Tested by

no test coverage detected