Build fix: missing initializer for member 'payload'
[lttng-tools.git] / src / common / event.cpp
index 6dca04def6e082527338da51694af1605546787a..37c346621b1dd956995259f4687e100d09ea153c 100644 (file)
@@ -5,28 +5,28 @@
  *
  */
 
-#include "common/compat/string.h"
-#include "common/macros.h"
-#include "lttng/lttng-error.h"
-#include <assert.h>
-#include <common/buffer-view.h>
-#include <common/dynamic-array.h>
-#include <common/dynamic-buffer.h>
-#include <common/error.h>
-#include <common/sessiond-comm/sessiond-comm.h>
-#include <common/align.h>
+#include <common/align.hpp>
+#include <common/buffer-view.hpp>
+#include <common/compat/string.hpp>
+#include <common/dynamic-array.hpp>
+#include <common/dynamic-buffer.hpp>
+#include <common/error.hpp>
+#include <common/macros.hpp>
+#include <common/sessiond-comm/sessiond-comm.hpp>
+
 #include <lttng/constant.h>
-#include <lttng/event-internal.h>
+#include <lttng/event-internal.hpp>
 #include <lttng/event.h>
-#include <lttng/userspace-probe-internal.h>
-#include <stdint.h>
-#include <string.h>
+#include <lttng/lttng-error.h>
+#include <lttng/userspace-probe-internal.hpp>
 
+namespace {
 struct event_list_element {
        struct lttng_event *event;
        struct lttng_event_exclusion *exclusions;
        char *filter_expression;
 };
+} /* namespace */
 
 static void event_list_destructor(void *ptr)
 {
@@ -43,7 +43,7 @@ struct lttng_event *lttng_event_copy(const struct lttng_event *event)
        struct lttng_event *new_event;
        struct lttng_event_extended *new_event_extended;
 
-       new_event = (lttng_event *) zmalloc(sizeof(*event));
+       new_event = zmalloc<lttng_event>();
        if (!new_event) {
                PERROR("Error allocating event structure");
                goto end;
@@ -56,7 +56,7 @@ struct lttng_event *lttng_event_copy(const struct lttng_event *event)
         * We need to create a new extended since the previous pointer is now
         * invalid.
         */
-       new_event_extended = (lttng_event_extended *) zmalloc(sizeof(*new_event_extended));
+       new_event_extended = zmalloc<lttng_event_extended>();
        if (!new_event_extended) {
                PERROR("Error allocating event extended structure");
                goto error;
@@ -77,10 +77,11 @@ static int lttng_event_probe_attr_serialize(
 {
        int ret;
        size_t symbol_name_len;
-       struct lttng_event_probe_attr_comm comm = { 0 };
+       struct lttng_event_probe_attr_comm comm = {};
 
-       symbol_name_len = lttng_strnlen(probe->symbol_name, LTTNG_SYMBOL_NAME_LEN);
-       if (symbol_name_len == LTTNG_SYMBOL_NAME_LEN) {
+       symbol_name_len = lttng_strnlen(
+                       probe->symbol_name, sizeof(probe->symbol_name));
+       if (symbol_name_len == sizeof(probe->symbol_name)) {
                /* Not null-termintated. */
                ret = -1;
                goto end;
@@ -112,10 +113,13 @@ static int lttng_event_function_attr_serialize(
 {
        int ret;
        size_t symbol_name_len;
-       struct lttng_event_function_attr_comm comm = { 0 };
+       struct lttng_event_function_attr_comm comm;
+
+       comm.symbol_name_len = 0;
 
-       symbol_name_len = lttng_strnlen(function->symbol_name, LTTNG_SYMBOL_NAME_LEN);
-       if (symbol_name_len == LTTNG_SYMBOL_NAME_LEN) {
+       symbol_name_len = lttng_strnlen(
+                       function->symbol_name, sizeof(function->symbol_name));
+       if (symbol_name_len == sizeof(function->symbol_name)) {
                /* Not null-termintated. */
                ret = -1;
                goto end;
@@ -157,8 +161,7 @@ static ssize_t lttng_event_probe_attr_create_from_payload(
        comm = (typeof(comm)) comm_view.buffer.data;
        offset += sizeof(*comm);
 
-       local_attr = (struct lttng_event_probe_attr *) zmalloc(
-                       sizeof(*local_attr));
+       local_attr = zmalloc<lttng_event_probe_attr>();
        if (local_attr == NULL) {
                ret = -1;
                goto end;
@@ -187,7 +190,7 @@ static ssize_t lttng_event_probe_attr_create_from_payload(
                }
 
                ret = lttng_strncpy(local_attr->symbol_name, name,
-                               LTTNG_SYMBOL_NAME_LEN);
+                               sizeof(local_attr->symbol_name));
                if (ret) {
                        ret = -1;
                        goto end;
@@ -222,8 +225,7 @@ static ssize_t lttng_event_function_attr_create_from_payload(
        comm = (typeof(comm)) view->buffer.data;
        offset += sizeof(*comm);
 
-       local_attr = (struct lttng_event_function_attr *) zmalloc(
-                       sizeof(*local_attr));
+       local_attr = zmalloc<lttng_event_function_attr>();
        if (local_attr == NULL) {
                ret = -1;
                goto end;
@@ -249,7 +251,7 @@ static ssize_t lttng_event_function_attr_create_from_payload(
                }
 
                ret = lttng_strncpy(local_attr->symbol_name, name,
-                               LTTNG_SYMBOL_NAME_LEN);
+                               sizeof(local_attr->symbol_name));
                if (ret) {
                        ret = -1;
                        goto end;
@@ -272,12 +274,12 @@ static ssize_t lttng_event_exclusions_create_from_payload(
                struct lttng_event_exclusion **exclusions)
 {
        ssize_t ret, offset = 0;
-       size_t size = (count * LTTNG_SYMBOL_NAME_LEN);
+       const size_t size = (count * LTTNG_SYMBOL_NAME_LEN);
        uint32_t i;
        const struct lttng_event_exclusion_comm *comm;
        struct lttng_event_exclusion *local_exclusions;
 
-       local_exclusions = (struct lttng_event_exclusion *) zmalloc(
+       local_exclusions = zmalloc<lttng_event_exclusion>(
                        sizeof(struct lttng_event_exclusion) + size);
        if (!local_exclusions) {
                ret = -1;
@@ -317,8 +319,8 @@ static ssize_t lttng_event_exclusions_create_from_payload(
                        goto end;
                }
 
-               ret = lttng_strncpy(local_exclusions->names[i],
-                               string, LTTNG_SYMBOL_NAME_LEN);
+               ret = lttng_strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(local_exclusions, i), string,
+                               sizeof(LTTNG_EVENT_EXCLUSION_NAME_AT(local_exclusions, i)));
                if (ret) {
                        ret = -1;
                        goto end;
@@ -406,8 +408,8 @@ ssize_t lttng_event_create_from_payload(struct lttng_payload_view *view,
                        goto end;
                }
 
-               ret = lttng_strncpy(
-                               local_event->name, name, LTTNG_SYMBOL_NAME_LEN);
+               ret = lttng_strncpy(local_event->name, name,
+                               sizeof(local_event->name));
                if (ret) {
                        ret = -1;
                        goto end;
@@ -510,8 +512,7 @@ deserialize_filter_expression:
                        goto end;
                }
 
-               local_bytecode = (struct lttng_bytecode *) zmalloc(
-                               event_comm->bytecode_len);
+               local_bytecode = zmalloc<lttng_bytecode>(event_comm->bytecode_len);
                if (!local_bytecode) {
                        ret = -1;
                        goto end;
@@ -700,7 +701,7 @@ int lttng_event_serialize(const struct lttng_event *event,
        unsigned int i;
        size_t header_offset, size_before_payload;
        size_t name_len;
-       struct lttng_event_comm event_comm = { 0 };
+       struct lttng_event_comm event_comm = {};
        struct lttng_event_comm *header;
 
        assert(event);
@@ -710,8 +711,8 @@ int lttng_event_serialize(const struct lttng_event *event,
        /* Save the header location for later in-place header update. */
        header_offset = payload->buffer.size;
 
-       name_len = lttng_strnlen(event->name, LTTNG_SYMBOL_NAME_LEN);
-       if (name_len == LTTNG_SYMBOL_NAME_LEN) {
+       name_len = lttng_strnlen(event->name, sizeof(event->name));
+       if (name_len == sizeof(event->name)) {
                /* Event name is not NULL-terminated. */
                ret = -1;
                goto end;
@@ -997,7 +998,8 @@ static ssize_t lttng_event_context_perf_counter_populate_from_payload(
                const struct lttng_payload_view *view,
                struct lttng_event_context *event_ctx)
 {
-       ssize_t ret, offset = 0;
+       int ret;
+       ssize_t consumed, offset = 0;
        const struct lttng_event_context_perf_counter_comm *comm;
        size_t name_len;
        const struct lttng_buffer_view comm_view = lttng_buffer_view_from_view(
@@ -1009,7 +1011,7 @@ static ssize_t lttng_event_context_perf_counter_populate_from_payload(
                        event_ctx->ctx == LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER);
 
        if (!lttng_buffer_view_is_valid(&comm_view)) {
-               ret = -1;
+               consumed = -1;
                goto end;
        }
 
@@ -1026,7 +1028,7 @@ static ssize_t lttng_event_context_perf_counter_populate_from_payload(
                                                name_len);
 
                if (!lttng_buffer_view_is_valid(&provider_name_view)) {
-                       ret = -1;
+                       consumed = -1;
                        goto end;
                }
 
@@ -1034,21 +1036,26 @@ static ssize_t lttng_event_context_perf_counter_populate_from_payload(
 
                if (!lttng_buffer_view_contains_string(
                                    &provider_name_view, name, name_len)) {
-                       ret = -1;
+                       consumed = -1;
                        goto end;
                }
 
-               lttng_strncpy(event_ctx->u.perf_counter.name, name, name_len);
+               ret = lttng_strncpy(event_ctx->u.perf_counter.name, name,
+                               sizeof(event_ctx->u.perf_counter.name));
+               if (ret) {
+                       consumed = -1;
+                       goto end;
+               }
                offset += name_len;
        }
 
        event_ctx->u.perf_counter.config = comm->config;
        event_ctx->u.perf_counter.type = comm->type;
 
-       ret = offset;
+       consumed = offset;
 
 end:
-       return ret;
+       return consumed;
 }
 
 ssize_t lttng_event_context_create_from_payload(
@@ -1072,8 +1079,7 @@ ssize_t lttng_event_context_create_from_payload(
        comm = (typeof(comm)) comm_view.data;
        offset += sizeof(*comm);
 
-       local_context = (struct lttng_event_context *)
-                       zmalloc(sizeof(*local_context));
+       local_context = zmalloc<lttng_event_context>();
        if (!local_context) {
                ret = -1;
                goto end;
@@ -1123,7 +1129,7 @@ static int lttng_event_context_app_serialize(
                struct lttng_payload *payload)
 {
        int ret;
-       struct lttng_event_context_app_comm comm = { 0 };
+       struct lttng_event_context_app_comm comm = {};
        size_t provider_len, ctx_len;
        const char *provider_name;
        const char *ctx_name;
@@ -1191,16 +1197,16 @@ static int lttng_event_context_perf_counter_serialize(
                struct lttng_payload *payload)
 {
        int ret;
-       struct lttng_event_context_perf_counter_comm comm = { 0 };
+       struct lttng_event_context_perf_counter_comm comm = {};
 
        assert(payload);
        assert(context);
 
        comm.config = context->config;
        comm.type = context->type;
-       comm.name_len = lttng_strnlen(context->name, LTTNG_SYMBOL_NAME_LEN);
+       comm.name_len = lttng_strnlen(context->name, sizeof(context->name));
 
-       if (comm.name_len == LTTNG_SYMBOL_NAME_LEN) {
+       if (comm.name_len == sizeof(context->name)) {
                ret = -1;
                goto end;
        }
@@ -1325,8 +1331,7 @@ ssize_t lttng_event_field_create_from_payload(
                offset += sizeof(*comm);
        }
 
-       local_event_field = (struct lttng_event_field *)
-                       zmalloc(sizeof(*local_event_field));
+       local_event_field = zmalloc<lttng_event_field>();
        if (!local_event_field) {
                ret = -1;
                goto end;
@@ -1389,7 +1394,8 @@ ssize_t lttng_event_field_create_from_payload(
        assert(name);
        assert(event);
 
-       if (lttng_strncpy(local_event_field->field_name, name , LTTNG_SYMBOL_NAME_LEN)) {
+       if (lttng_strncpy(local_event_field->field_name, name,
+                       sizeof(local_event_field->field_name))) {
                ret = -1;
                goto end;
        }
@@ -1412,7 +1418,7 @@ int lttng_event_field_serialize(const struct lttng_event_field *field,
        int ret;
        size_t header_offset, size_before_event;
        size_t name_len;
-       struct lttng_event_field_comm event_field_comm = { 0 };
+       struct lttng_event_field_comm event_field_comm = {};
        struct lttng_event_field_comm *header;
 
        assert(field);
@@ -1421,8 +1427,8 @@ int lttng_event_field_serialize(const struct lttng_event_field *field,
        /* Save the header location for later in-place header update. */
        header_offset = payload->buffer.size;
 
-       name_len = strnlen(field->field_name, LTTNG_SYMBOL_NAME_LEN);
-       if (name_len == LTTNG_SYMBOL_NAME_LEN) {
+       name_len = strnlen(field->field_name, sizeof(field->field_name));
+       if (name_len == sizeof(field->field_name)) {
                /* Event name is not NULL-terminated. */
                ret = -1;
                goto end;
@@ -1483,6 +1489,9 @@ static enum lttng_error_code compute_flattened_size(
        /* The basic struct lttng_event */
        storage_req = event_count * sizeof(struct lttng_event);
 
+       /* The struct·lttng_event_extended */
+       storage_req += event_count * sizeof(struct lttng_event_extended);
+
        for (i = 0; i < event_count; i++) {
                int probe_storage_req = 0;
                const struct event_list_element *element = (const struct event_list_element *)
@@ -1503,10 +1512,6 @@ static enum lttng_error_code compute_flattened_size(
                        probe_storage_req = ret;
                }
 
-               /* The struct·lttng_event_extended */
-               storage_req += event_count *
-                       sizeof(struct lttng_event_extended);
-
                if (element->filter_expression) {
                        storage_req += strlen(element->filter_expression) + 1;
                }
@@ -1707,8 +1712,7 @@ static enum lttng_error_code event_list_create_from_payload(
                ssize_t event_size;
                struct lttng_payload_view event_view =
                                lttng_payload_view_from_view(view, offset, -1);
-               struct event_list_element *element =
-                               (struct event_list_element *) zmalloc(sizeof(*element));
+               struct event_list_element *element = zmalloc<event_list_element>();
 
                if (!element) {
                        ret_code = LTTNG_ERR_NOMEM;
@@ -1864,7 +1868,7 @@ static enum lttng_error_code event_field_list_create_from_payload(
        assert(view);
        assert(event_field_list);
 
-       list = (struct lttng_dynamic_pointer_array *) zmalloc(sizeof(*list));
+       list = zmalloc<lttng_dynamic_pointer_array>();
        if (!list) {
                ret_code = LTTNG_ERR_NOMEM;
                goto end;
This page took 0.029488 seconds and 4 git commands to generate.