From 574e2671c7fa7b50db98d06c8ec62595eee338a6 Mon Sep 17 00:00:00 2001 From: Michael Barker Date: Mon, 17 Jun 2024 12:21:57 -1100 Subject: [PATCH] [C] Handle flexible array members in MSVC. --- .../src/main/c/aeron_driver_conductor_proxy.c | 12 ++++++++++-- aeron-driver/src/main/c/aeron_network_publication.c | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/aeron-driver/src/main/c/aeron_driver_conductor_proxy.c b/aeron-driver/src/main/c/aeron_driver_conductor_proxy.c index 610e049c771..24919729b0e 100644 --- a/aeron-driver/src/main/c/aeron_driver_conductor_proxy.c +++ b/aeron-driver/src/main/c/aeron_driver_conductor_proxy.c @@ -19,6 +19,8 @@ #include "aeron_alloc.h" #include "aeron_driver_conductor.h" +#define AERON_COMMAND_PUBLICATION_ERROR_MAX_LENGTH (sizeof(aeron_command_publication_error_t) + AERON_ERROR_MAX_MESSAGE_LENGTH) + void aeron_driver_conductor_proxy_offer(aeron_driver_conductor_proxy_t *conductor_proxy, void *cmd, size_t length) { aeron_rb_write_result_t result; @@ -260,6 +262,11 @@ void aeron_driver_conductor_proxy_on_release_resource( } } +static void aeron_driver_conductor_proxy_null_terminate(uint8_t *text, int index) +{ + text[index] = '\0'; +} + void aeron_driver_conductor_proxy_on_publication_error( aeron_driver_conductor_proxy_t *conductor_proxy, const int64_t registration_id, @@ -267,7 +274,7 @@ void aeron_driver_conductor_proxy_on_publication_error( int32_t error_length, const uint8_t *error_text) { - uint8_t buffer[offsetof(aeron_command_publication_error_t, error_text[AERON_ERROR_MAX_MESSAGE_LENGTH + 1])]; + uint8_t buffer[AERON_COMMAND_PUBLICATION_ERROR_MAX_LENGTH]; aeron_command_publication_error_t *error = (aeron_command_publication_error_t *)buffer; error_length = error_length <= AERON_ERROR_MAX_MESSAGE_LENGTH ? error_length : AERON_ERROR_MAX_MESSAGE_LENGTH; @@ -276,7 +283,8 @@ void aeron_driver_conductor_proxy_on_publication_error( error->registration_id = registration_id; error->error_code = error_code; memcpy(error->error_text, error_text, (size_t)error_length); - error->error_text[error_length] = '\0'; + aeron_driver_conductor_proxy_null_terminate(error->error_text, error_length); + size_t cmd_length = sizeof(aeron_command_publication_error_t) + error_length + 1; if (AERON_THREADING_MODE_IS_SHARED_OR_INVOKER(conductor_proxy->threading_mode)) diff --git a/aeron-driver/src/main/c/aeron_network_publication.c b/aeron-driver/src/main/c/aeron_network_publication.c index 095baedabdc..5bb41ab3219 100644 --- a/aeron-driver/src/main/c/aeron_network_publication.c +++ b/aeron-driver/src/main/c/aeron_network_publication.c @@ -307,7 +307,7 @@ int aeron_network_publication_create( _pub->is_response = AERON_UDP_CHANNEL_CONTROL_MODE_RESPONSE == endpoint->conductor_fields.udp_channel->control_mode; _pub->response_correlation_id = params->response_correlation_id; - aeron_int64_counter_map_init(&_pub->receiver_liveness_tracker, AERON_NULL_VALUE, 16, 0.6); + aeron_int64_counter_map_init(&_pub->receiver_liveness_tracker, AERON_NULL_VALUE, 16, 0.6f); *publication = _pub;