X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fevent.cpp;h=f33518eee4eece45c2c8ce762cb22765a682209b;hb=fa9870ceddc6f5ddd4bbf8cda2a87365b78fdf0e;hp=601c6ac1fa5f1d2de8c13790102b97c994ab820c;hpb=97f9ed7d7da933aaf3c25c9a8a7fe12b5b9f8d58;p=lttng-tools.git diff --git a/src/common/event.cpp b/src/common/event.cpp index 601c6ac1f..f33518eee 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -5,28 +5,28 @@ * */ -#include "common/compat/string.h" -#include "common/macros.h" -#include "lttng/lttng-error.h" -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include + #include -#include +#include #include -#include -#include -#include +#include +#include +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(); 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(); if (!new_event_extended) { PERROR("Error allocating event extended structure"); goto error; @@ -113,7 +113,9 @@ 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, sizeof(function->symbol_name)); @@ -159,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(); if (local_attr == NULL) { ret = -1; goto end; @@ -224,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(); if (local_attr == NULL) { ret = -1; goto end; @@ -274,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( sizeof(struct lttng_event_exclusion) + size); if (!local_exclusions) { ret = -1; @@ -319,8 +319,8 @@ static ssize_t lttng_event_exclusions_create_from_payload( goto end; } - ret = lttng_strncpy(local_exclusions->names[i], string, - sizeof(local_exclusions->names[i])); + 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; @@ -512,8 +512,7 @@ deserialize_filter_expression: goto end; } - local_bytecode = (struct lttng_bytecode *) zmalloc( - event_comm->bytecode_len); + local_bytecode = zmalloc(event_comm->bytecode_len); if (!local_bytecode) { ret = -1; goto end; @@ -767,9 +766,9 @@ int lttng_event_serialize(const struct lttng_event *event, for (i = 0; i < exclusion_count; i++) { const size_t exclusion_len = lttng_strnlen( *(exclusion_list + i), LTTNG_SYMBOL_NAME_LEN); - const struct lttng_event_exclusion_comm exclusion_header = { - .len = (uint32_t) exclusion_len + 1, - }; + struct lttng_event_exclusion_comm exclusion_header; + + exclusion_header.len = (uint32_t) exclusion_len + 1; if (exclusion_len == LTTNG_SYMBOL_NAME_LEN) { /* Exclusion is not NULL-terminated. */ @@ -1080,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(); if (!local_context) { ret = -1; goto end; @@ -1239,7 +1237,9 @@ int lttng_event_context_serialize(struct lttng_event_context *context, struct lttng_payload *payload) { int ret; - struct lttng_event_context_comm context_comm = { 0 }; + struct lttng_event_context_comm context_comm; + + context_comm.type = 0; assert(context); assert(payload); @@ -1333,8 +1333,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(); if (!local_event_field) { ret = -1; goto end; @@ -1715,8 +1714,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(); if (!element) { ret_code = LTTNG_ERR_NOMEM; @@ -1872,7 +1870,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(); if (!list) { ret_code = LTTNG_ERR_NOMEM; goto end;