Clean-up: suppress bogus scan-build warning
[lttng-tools.git] / src / common / trace-chunk.c
index dbab99d192876a73ce49be5975b674f55ec4e60e..908bdf9fee148836202af6738167a58dec28f20b 100644 (file)
@@ -91,8 +91,8 @@ struct lttng_trace_chunk {
 
 /* A trace chunk is uniquely identified by its (session id, chunk id) tuple. */
 struct lttng_trace_chunk_registry_element {
-       uint64_t session_id;
        struct lttng_trace_chunk chunk;
+       uint64_t session_id;
        /* Weak and only set when added. */
        struct lttng_trace_chunk_registry *registry;
        struct cds_lfht_node trace_chunk_registry_ht_node;
@@ -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;
@@ -366,12 +367,14 @@ enum lttng_trace_chunk_status lttng_trace_chunk_set_close_timestamp(
                goto end;
        }
        LTTNG_OPTIONAL_SET(&chunk->timestamp_close, close_ts);
-       free(chunk->name);
-       chunk->name = generate_chunk_name(LTTNG_OPTIONAL_GET(chunk->id),
-                       LTTNG_OPTIONAL_GET(chunk->timestamp_creation),
-                       &close_ts);
-       if (!chunk->name) {
-               status = LTTNG_TRACE_CHUNK_STATUS_ERROR;
+       if (!chunk->name_overridden) {
+               free(chunk->name);
+               chunk->name = generate_chunk_name(LTTNG_OPTIONAL_GET(chunk->id),
+                               LTTNG_OPTIONAL_GET(chunk->timestamp_creation),
+                               &close_ts);
+               if (!chunk->name) {
+                       status = LTTNG_TRACE_CHUNK_STATUS_ERROR;
+               }
        }
 end:
        pthread_mutex_unlock(&chunk->lock);
@@ -408,7 +411,7 @@ bool is_valid_chunk_name(const char *name)
                return false;
        }
 
-       len = strnlen(name, LTTNG_NAME_MAX);
+       len = lttng_strnlen(name, LTTNG_NAME_MAX);
        if (len == 0 || len == LTTNG_NAME_MAX) {
                return false;
        }
@@ -654,7 +657,7 @@ int add_top_level_directory_unique(struct lttng_trace_chunk *chunk,
        }
 
        if (!found) {
-               char *copy = strndup(new_path, new_path_top_level_len);
+               char *copy = lttng_strndup(new_path, new_path_top_level_len);
 
                DBG("Adding new top-level directory \"%s\" to trace chunk \"%s\"",
                                new_path, chunk->name ? : "(unnamed)");
@@ -1094,7 +1097,7 @@ end:
        return registry;
 error:
        lttng_trace_chunk_registry_destroy(registry);
-       goto end;
+       return NULL;
 }
 
 LTTNG_HIDDEN
This page took 0.023824 seconds and 4 git commands to generate.