diff options
| author | chenzizhan <[email protected]> | 2024-04-18 15:38:26 +0800 |
|---|---|---|
| committer | chenzizhan <[email protected]> | 2024-04-18 15:38:26 +0800 |
| commit | d1375c9ce15ea764272a658072666b0ed519dc94 (patch) | |
| tree | 7fd524254a205912ffb18cb0bc708c2ffef04464 | |
| parent | bab8c29dc98dfa4515fffa077e0f234b541560f3 (diff) | |
fix core when tag is emptyv4.5.6c
| -rw-r--r-- | src/exporter/cjson_exporter.c | 3 | ||||
| -rw-r--r-- | test/test_easy_fs.cpp | 6 |
2 files changed, 6 insertions, 3 deletions
diff --git a/src/exporter/cjson_exporter.c b/src/exporter/cjson_exporter.c index c9a410d..206f7b1 100644 --- a/src/exporter/cjson_exporter.c +++ b/src/exporter/cjson_exporter.c @@ -379,6 +379,9 @@ void write_delta_to_json(struct fieldstat_json_exporter *exporter, struct cellwi { // for every tag_field_pair, get the tag json string const char *tag_json = json_writer_unwrap(tag_field_pair->cjson_tags); + if (tag_json == NULL) { + tag_json = "\a\t\a"; // just a dummy string + } for (int j = 0; j < tag_field_pair->n_metric; j++) { if (tag_field_pair->metric_pairs[j]->type != TAG_INTEGER) { // only counter type need to write delta continue; diff --git a/test/test_easy_fs.cpp b/test/test_easy_fs.cpp index 0595593..d3f45b7 100644 --- a/test/test_easy_fs.cpp +++ b/test/test_easy_fs.cpp @@ -42,15 +42,15 @@ TEST(test_easy_fieldstat, output_to_buff) TEST(test_easy_fieldstat, output_to_buff_with_delta) { - struct fieldstat_easy *fse = fieldstat_easy_new(10, NULL, &TEST_TAG_STRING, 1); + struct fieldstat_easy *fse = fieldstat_easy_new(1, NULL, NULL, 0); fieldstat_easy_enable_delta_in_active_output(fse); fieldstat_easy_register_counter(fse, "metric counter"); - fieldstat_easy_counter_incrby(fse, 0, 0, &TEST_TAG_INT, 1, 1); + fieldstat_easy_counter_incrby(fse, 0, 0, NULL, 0, 1); char *buff = NULL; size_t buff_len = 0; fieldstat_easy_output(fse, &buff, &buff_len); free(buff); - fieldstat_easy_counter_incrby(fse, 0, 0, &TEST_TAG_INT, 1, 1); + fieldstat_easy_counter_incrby(fse, 0, 0, NULL, 0, 1); fieldstat_easy_output(fse, &buff, &buff_len); cJSON *root = cJSON_Parse(buff); |
