Skip to content

Commit

Permalink
[C] Handle flexible array members in MSVC.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeb01 committed Jun 18, 2024
1 parent 9bd7da6 commit 574e267
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions aeron-driver/src/main/c/aeron_driver_conductor_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -260,14 +262,19 @@ 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,
int32_t error_code,
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;

Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion aeron-driver/src/main/c/aeron_network_publication.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 574e267

Please sign in to comment.