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