| 534 | } |
| 535 | |
| 536 | static 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 | |
| 559 | static void json_append_data(lua_State *l, json_config_t *cfg, |
| 560 | int current_depth, strbuf_t *json); |
no test coverage detected