| 713 | } |
| 714 | |
| 715 | static 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 | |
| 738 | static void json_append_data(lua_State *l, json_config_t *cfg, |
| 739 | int current_depth, strbuf_t *json); |
no test coverage detected