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/rrdcalc.c | |
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/rrdcalc.c')
-rw-r--r-- | database/rrdcalc.c | 14 |
1 files changed, 8 insertions, 6 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); |