Check neu_json_decode_array_size_by_json return value close #334

This commit is contained in:
lixiumei
2022-03-21 15:20:22 +08:00
parent dda292d2a3
commit 47eba78d75
6 changed files with 39 additions and 7 deletions
+5 -1
View File
@@ -97,7 +97,11 @@ int neu_json_decode_write_req(char *buf, neu_json_write_req_t **result)
req->group_config_name = req_elems[1].v.val_str;
req->n_tag = neu_json_decode_array_size_by_json(json_obj, "tags");
req->tags = calloc(req->n_tag, sizeof(neu_json_write_req_tag_t));
if (req->n_tag < 0) {
goto decode_fail;
}
req->tags = calloc(req->n_tag, sizeof(neu_json_write_req_tag_t));
neu_json_write_req_tag_t *p_tag = req->tags;
for (int i = 0; i < req->n_tag; i++) {
neu_json_elem_t tag_elems[] = { {
+15 -3
View File
@@ -58,7 +58,11 @@ int neu_json_decode_add_tags_req(char *buf, neu_json_add_tags_req_t **result)
req->group_config_name = req_elems[1].v.val_str;
req->n_tag = neu_json_decode_array_size_by_json(json_obj, "tags");
req->tags = calloc(req->n_tag, sizeof(neu_json_add_tags_req_tag_t));
if (req->n_tag < 0) {
goto decode_fail;
}
req->tags = calloc(req->n_tag, sizeof(neu_json_add_tags_req_tag_t));
neu_json_add_tags_req_tag_t *p_tag = req->tags;
for (int i = 0; i < req->n_tag; i++) {
neu_json_elem_t tag_elems[] = { {
@@ -154,7 +158,11 @@ int neu_json_decode_del_tags_req(char *buf, neu_json_del_tags_req_t **result)
req->group_config_name = req_elems[1].v.val_str;
req->n_id = neu_json_decode_array_size_by_json(json_obj, "ids");
req->ids = calloc(req->n_id, sizeof(neu_json_del_tags_req_id_t));
if (req->n_id < 0) {
goto decode_fail;
}
req->ids = calloc(req->n_id, sizeof(neu_json_del_tags_req_id_t));
neu_json_del_tags_req_id_t *p_id = req->ids;
for (int i = 0; i < req->n_id; i++) {
neu_json_elem_t id_elems[] = { {
@@ -337,7 +345,11 @@ int neu_json_decode_update_tags_req(char * buf,
req->group_config_name = req_elems[1].v.val_str;
req->n_tag = neu_json_decode_array_size_by_json(json_obj, "tags");
req->tags = calloc(req->n_tag, sizeof(neu_json_update_tags_req_tag_t));
if (req->n_tag < 0) {
goto decode_fail;
}
req->tags = calloc(req->n_tag, sizeof(neu_json_update_tags_req_tag_t));
neu_json_update_tags_req_tag_t *p_tag = req->tags;
for (int i = 0; i < req->n_tag; i++) {
neu_json_elem_t tag_elems[] = { {
+5 -1
View File
@@ -85,7 +85,11 @@ int neu_json_decode_node_req(char *buf, neu_json_node_req_t **result)
json_obj = neu_json_decode_new(buf);
req->n_node = neu_json_decode_array_size_by_json(json_obj, "nodes");
req->nodes = calloc(req->n_node, sizeof(neu_json_node_req_node_t));
if (req->n_node < 0) {
goto decode_fail;
}
req->nodes = calloc(req->n_node, sizeof(neu_json_node_req_node_t));
neu_json_node_req_node_t *p_node = req->nodes;
for (int i = 0; i < req->n_node; i++) {
neu_json_elem_t node_elems[] = { {
+5 -1
View File
@@ -41,7 +41,11 @@ int neu_json_decode_datatag_req(char *buf, neu_json_datatag_req_t **result)
json_obj = neu_json_decode_new(buf);
req->n_tag = neu_json_decode_array_size_by_json(json_obj, "tags");
req->tags = calloc(req->n_tag, sizeof(neu_json_datatag_req_tag_t));
if (req->n_tag < 0) {
goto decode_fail;
}
req->tags = calloc(req->n_tag, sizeof(neu_json_datatag_req_tag_t));
neu_json_datatag_req_tag_t *p_tag = req->tags;
for (int i = 0; i < req->n_tag; i++) {
neu_json_elem_t tag_elems[] = { {
+5 -1
View File
@@ -41,7 +41,11 @@ int neu_json_decode_plugin_req(char *buf, neu_json_plugin_req_t **result)
json_obj = neu_json_decode_new(buf);
req->n_plugin = neu_json_decode_array_size_by_json(json_obj, "plugins");
req->plugins = calloc(req->n_plugin, sizeof(neu_json_plugin_req_plugin_t));
if (req->n_plugin < 0) {
goto decode_fail;
}
req->plugins = calloc(req->n_plugin, sizeof(neu_json_plugin_req_plugin_t));
neu_json_plugin_req_plugin_t *p_plugin = req->plugins;
for (int i = 0; i < req->n_plugin; i++) {
neu_json_elem_t plugin_elems[] = { {
+4
View File
@@ -44,6 +44,10 @@ int neu_json_decode_subscriptions_req(char * buf,
req->n_subscription =
neu_json_decode_array_size_by_json(json_obj, "subscriptions");
if (req->n_subscription < 0) {
goto decode_fail;
}
req->subscriptions = calloc(
req->n_subscription, sizeof(neu_json_subscriptions_req_subscription_t));
neu_json_subscriptions_req_subscription_t *p_subscription =