aboutsummaryrefslogtreecommitdiff
path: root/lua_cjson.c
diff options
context:
space:
mode:
Diffstat (limited to 'lua_cjson.c')
-rw-r--r--lua_cjson.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/lua_cjson.c b/lua_cjson.c
index 63b3d06..f888644 100644
--- a/lua_cjson.c
+++ b/lua_cjson.c
@@ -1017,13 +1017,22 @@ static void json_throw_parse_error(lua_State *l, json_parse_t *json,
1017 exp, found, token->index + 1); 1017 exp, found, token->index + 1);
1018} 1018}
1019 1019
1020static void json_decode_checkstack(lua_State *l, json_parse_t *json, int n)
1021{
1022 if (lua_checkstack(l, n))
1023 return;
1024
1025 strbuf_free(json->tmp);
1026 luaL_error(l, "Too many nested data structures");
1027}
1028
1020static void json_parse_object_context(lua_State *l, json_parse_t *json) 1029static void json_parse_object_context(lua_State *l, json_parse_t *json)
1021{ 1030{
1022 json_token_t token; 1031 json_token_t token;
1023 1032
1024 /* 3 slots required: 1033 /* 3 slots required:
1025 * .., table, key, value */ 1034 * .., table, key, value */
1026 luaL_checkstack(l, 3, "too many nested data structures"); 1035 json_decode_checkstack(l, json, 3);
1027 1036
1028 lua_newtable(l); 1037 lua_newtable(l);
1029 1038
@@ -1072,7 +1081,7 @@ static void json_parse_array_context(lua_State *l, json_parse_t *json)
1072 1081
1073 /* 2 slots required: 1082 /* 2 slots required:
1074 * .., table, value */ 1083 * .., table, value */
1075 luaL_checkstack(l, 2, "too many nested data structures"); 1084 json_decode_checkstack(l, json, 2);
1076 1085
1077 lua_newtable(l); 1086 lua_newtable(l);
1078 1087