From 6e7e504882cc5ca7549459d1ecafa69d3242d2d5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Mon, 9 Sep 2019 12:14:54 -0400 Subject: [PATCH] Clean-up: format using remaining buffer len rather than total len MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit end_datetime_suffix is has an extra byte to contain a '-' prefix. This means that its effective length is ISO8601_STR_LEN and not its sizeof(). This is not considered a fix as time_to_iso8601_str() does not write more than ISO8601_STR_LEN (for time being). The ISO8601_STR_LEN macro is used for the buffer lengths for clarity; no behaviour change is intended. Signed-off-by: Jérémie Galarneau --- src/common/trace-chunk.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/common/trace-chunk.c b/src/common/trace-chunk.c index 9f0919a88..f7a4372b4 100644 --- a/src/common/trace-chunk.c +++ b/src/common/trace-chunk.c @@ -165,8 +165,9 @@ char *generate_chunk_name(uint64_t chunk_id, time_t creation_timestamp, { int ret = 0; char *new_name= NULL; - char start_datetime[sizeof("YYYYmmddTHHMMSS+HHMM")] = {}; - char end_datetime_suffix[sizeof("-YYYYmmddTHHMMSS+HHMM")] = {}; + char start_datetime[ISO8601_STR_LEN] = {}; + /* Add 1 for a '-' prefix. */ + char end_datetime_suffix[ISO8601_STR_LEN + 1] = {}; ret = time_to_iso8601_str( creation_timestamp, @@ -180,7 +181,7 @@ char *generate_chunk_name(uint64_t chunk_id, time_t creation_timestamp, ret = time_to_iso8601_str( *close_timestamp, end_datetime_suffix + 1, - sizeof(end_datetime_suffix)); + sizeof(end_datetime_suffix) - 1); if (ret) { ERR("Failed to format trace chunk end date time"); goto error; -- 2.34.1