diff options
author | Emmanuel Vasilakis <mrzammler@mm.st> | 2023-01-05 15:42:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-05 15:42:55 +0200 |
commit | 6898558b7278fa6ac80a2c91b2854d08b0360fe3 (patch) | |
tree | 5a17e8825d530315b0ee4ad08d8378cffba4e3d4 /database | |
parent | 6fc5c4f51d0406090398f471057f7f11646b838f (diff) |
Use brackets around info variables (#14206)
* use brackets around vars
* update doc
* change doc
* try fix codacy
* fix 2
Diffstat (limited to 'database')
-rw-r--r-- | database/rrdcalc.c | 14 | ||||
-rw-r--r-- | database/rrdcalc.h | 4 |
2 files changed, 10 insertions, 8 deletions
diff --git a/database/rrdcalc.c b/database/rrdcalc.c index aad945a907..45338a8260 100644 --- a/database/rrdcalc.c +++ b/database/rrdcalc.c @@ -74,18 +74,16 @@ static STRING *rrdcalc_replace_variables_with_rrdset_labels(const char *line, RR char var[RRDCALC_VAR_MAX]; char *m, *lbl_value = NULL; - while ((m = strchr(temp + pos, '$'))) { + while ((m = strchr(temp + pos, '$')) && *(m+1) == '{') { int i = 0; char *e = m; while (*e) { + var[i++] = *e; - if (*e == ' ' || i == RRDCALC_VAR_MAX - 1) + if (*e == '}' || i == RRDCALC_VAR_MAX - 1) break; - else - var[i] = *e; e++; - i++; } var[i] = '\0'; @@ -97,8 +95,12 @@ static STRING *rrdcalc_replace_variables_with_rrdset_labels(const char *line, RR temp = buf; } else if (!strncmp(var, RRDCALC_VAR_LABEL, RRDCALC_VAR_LABEL_LEN)) { + char label_val[RRDCALC_VAR_MAX + 1] = { 0 }; + strcpy(label_val, var+RRDCALC_VAR_LABEL_LEN); + label_val[i - RRDCALC_VAR_LABEL_LEN - 1] = '\0'; + if(likely(rc->rrdset && rc->rrdset->rrdlabels)) { - rrdlabels_get_value_to_char_or_null(rc->rrdset->rrdlabels, &lbl_value, var+RRDCALC_VAR_LABEL_LEN); + rrdlabels_get_value_to_char_or_null(rc->rrdset->rrdlabels, &lbl_value, label_val); if (lbl_value) { char *buf = find_and_replace(temp, var, lbl_value, m); freez(temp); diff --git a/database/rrdcalc.h b/database/rrdcalc.h index a25c05cc6e..08d8beee20 100644 --- a/database/rrdcalc.h +++ b/database/rrdcalc.h @@ -251,8 +251,8 @@ void rrdcalc_rrdhost_index_init(RRDHOST *host); void rrdcalc_rrdhost_index_destroy(RRDHOST *host); #define RRDCALC_VAR_MAX 100 -#define RRDCALC_VAR_FAMILY "$family" -#define RRDCALC_VAR_LABEL "$label:" +#define RRDCALC_VAR_FAMILY "${family}" +#define RRDCALC_VAR_LABEL "${label:" #define RRDCALC_VAR_LABEL_LEN (sizeof(RRDCALC_VAR_LABEL)-1) #endif //NETDATA_RRDCALC_H |