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