Skip to content

Commit

Permalink
metrics: Fix size error
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed Jun 18, 2024
1 parent f6b4287 commit fe76dce
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/flb_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ struct flb_metrics *flb_metrics_create(const char *title)
}
metrics->count = 0;

title_len = snprintf(NULL, 0, "%s\n", title);
allocated_title = flb_calloc(title_len, sizeof(char));
title_len = snprintf(NULL, 0, "%s", title);
allocated_title = flb_calloc(title_len + 1, sizeof(char));
if (allocated_title == NULL) {
flb_free(metrics);
return NULL;
Expand All @@ -114,7 +114,7 @@ struct flb_metrics *flb_metrics_create(const char *title)
int flb_metrics_title(const char *title, struct flb_metrics *metrics)
{
int ret;
size_t size = sizeof(metrics->title);
size_t size = snprintf(NULL, 0, "%s", title);

ret = snprintf(metrics->title, size, "%s", title);
if (ret == -1) {
Expand Down

0 comments on commit fe76dce

Please sign in to comment.