MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / json_check_encode_depth

Function json_check_encode_depth

deps/lua/src/lua_cjson.c:536–557  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

json_append_dataFunction · 0.85

Calls 3

lua_checkstackFunction · 0.85
strbuf_freeFunction · 0.85
luaL_errorFunction · 0.85

Tested by

no test coverage detected