X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Factions%2Fpath.cpp;h=612ade8c31a69e7696312c9882c145b1700335e4;hb=5611a81d91d828e052b4be76bd9bd725d2088656;hp=0c8181896dfc612614baebf3775d5a37c250c2e7;hpb=c9e313bc594f40a86eed237dce222c0fc99c957f;p=lttng-tools.git diff --git a/src/common/actions/path.cpp b/src/common/actions/path.cpp index 0c8181896..612ade8c3 100644 --- a/src/common/actions/path.cpp +++ b/src/common/actions/path.cpp @@ -7,10 +7,12 @@ #include +namespace { struct lttng_action_path_comm { uint32_t index_count; uint64_t indexes[]; } LTTNG_PACKED; +} /* namespace */ struct lttng_action_path *lttng_action_path_create( const uint64_t *indexes, size_t index_count) @@ -23,7 +25,7 @@ struct lttng_action_path *lttng_action_path_create( goto error; } - path = (lttng_action_path *) zmalloc(sizeof(*path)); + path = zmalloc(); if (!path) { goto error; } @@ -96,32 +98,25 @@ end: } int lttng_action_path_copy(const struct lttng_action_path *src, - struct lttng_action_path *dst) + struct lttng_action_path **dst) { int ret; - size_t i, src_count; + struct lttng_action_path *new_path; LTTNG_ASSERT(src); LTTNG_ASSERT(dst); - lttng_dynamic_array_init(&dst->indexes, sizeof(uint64_t), NULL); - src_count = lttng_dynamic_array_get_count(&src->indexes); - - for (i = 0; i < src_count; i++) { - const void *index = lttng_dynamic_array_get_element( - &src->indexes, i); - - ret = lttng_dynamic_array_add_element(&dst->indexes, index); - if (ret) { - goto error; - } + new_path = lttng_action_path_create( + (uint64_t *) lttng_dynamic_array_get_element( + &src->indexes, 0), + lttng_dynamic_array_get_count(&src->indexes)); + if (!new_path) { + ret = -1; + } else { + ret = 0; + *dst = new_path; } - ret = 0; - goto end; -error: - lttng_dynamic_array_reset(&dst->indexes); -end: return ret; } @@ -193,9 +188,7 @@ int lttng_action_path_serialize(const struct lttng_action_path *action_path, goto end; } - comm = { - .index_count = (uint32_t) index_count, - }; + comm.index_count = (uint32_t) index_count; ret = lttng_dynamic_buffer_append(&payload->buffer, &comm, sizeof(struct lttng_action_path_comm));