From ea267be12b02903dfb5ead6c95d5ec8262ff817f Mon Sep 17 00:00:00 2001 From: Takahiro Yamashita Date: Sat, 5 Aug 2023 10:56:20 +0900 Subject: [PATCH] log_event_encoder: define flb_log_event_size_t Windows x86_64 passes dword size_t and it causes encoder error. Since size_t should be unsigned __int64. We define dword flb_log_event_size_t to prevent invalid casting as a workaround. Signed-off-by: Takahiro Yamashita --- include/fluent-bit/flb_log_event_encoder.h | 18 +++++----- .../flb_log_event_encoder_primitives.h | 29 +++++++++------ src/flb_log_event_encoder_primitives.c | 36 +++++++++---------- 3 files changed, 46 insertions(+), 37 deletions(-) diff --git a/include/fluent-bit/flb_log_event_encoder.h b/include/fluent-bit/flb_log_event_encoder.h index 37f4500e80f..d6f3ea03ddb 100644 --- a/include/fluent-bit/flb_log_event_encoder.h +++ b/include/fluent-bit/flb_log_event_encoder.h @@ -84,31 +84,31 @@ #define FLB_LOG_EVENT_STRING_LENGTH_VALUE(length) \ (flb_log_event_type_t) FLB_LOG_EVENT_STRING_LENGTH_VALUE_TYPE, \ - (size_t) length + (flb_log_event_size_t) length #define FLB_LOG_EVENT_STRING_BODY_VALUE(buffer, length) \ (flb_log_event_type_t) FLB_LOG_EVENT_STRING_BODY_VALUE_TYPE, \ (char *) buffer, \ - (size_t) length + (flb_log_event_size_t) length #define FLB_LOG_EVENT_BINARY_LENGTH_VALUE(length) \ (flb_log_event_type_t) FLB_LOG_EVENT_BINARY_LENGTH_VALUE_TYPE, \ - (size_t) length + (flb_log_event_size_t) length #define FLB_LOG_EVENT_BINARY_BODY_VALUE(buffer, length) \ (flb_log_event_type_t) FLB_LOG_EVENT_BINARY_BODY_VALUE_TYPE, \ (char *) buffer, \ - (size_t) length + (flb_log_event_size_t) length #define FLB_LOG_EVENT_EXT_LENGTH_VALUE(type_, length) \ (flb_log_event_type_t) FLB_LOG_EVENT_EXT_LENGTH_VALUE_TYPE, \ (int8_t) type_, \ - (size_t) length + (flb_log_event_size_t) length #define FLB_LOG_EVENT_EXT_BODY_VALUE(buffer, length) \ (flb_log_event_type_t) FLB_LOG_EVENT_EXT_BODY_VALUE_TYPE, \ (char *) buffer, \ - (size_t) length + (flb_log_event_size_t) length #define FLB_LOG_EVENT_TIMESTAMP_VALUE(value) \ (flb_log_event_type_t) FLB_LOG_EVENT_TIMESTAMP_VALUE_TYPE, \ @@ -180,11 +180,11 @@ #define FLB_LOG_EVENT_MSGPACK_RAW_VALUE(buffer, length) \ (flb_log_event_type_t) FLB_LOG_EVENT_MSGPACK_RAW_VALUE_TYPE, \ (char *) buffer, \ - (size_t) length + (flb_log_event_size_t) length #define FLB_LOG_EVENT_STRING_VALUE(buffer, length) \ - FLB_LOG_EVENT_STRING_LENGTH_VALUE((size_t)length), \ - FLB_LOG_EVENT_STRING_BODY_VALUE(buffer, (size_t)length) + FLB_LOG_EVENT_STRING_LENGTH_VALUE((flb_log_event_size_t)length), \ + FLB_LOG_EVENT_STRING_BODY_VALUE(buffer, (flb_log_event_size_t)length) #define FLB_LOG_EVENT_BINARY_VALUE(buffer, length) \ FLB_LOG_EVENT_BINARY_LENGTH_VALUE(length), \ diff --git a/include/fluent-bit/flb_log_event_encoder_primitives.h b/include/fluent-bit/flb_log_event_encoder_primitives.h index af6caecdfd2..b0142073aaa 100644 --- a/include/fluent-bit/flb_log_event_encoder_primitives.h +++ b/include/fluent-bit/flb_log_event_encoder_primitives.h @@ -20,6 +20,15 @@ #ifndef FLB_LOG_EVENT_ENCODER_PRIMITIVES_H #define FLB_LOG_EVENT_ENCODER_PRIMITIVES_H +#ifdef FLB_SYSTEM_WINDOWS +/* Windows x86_64 passes size_t as dword and it causes encoder error. + * We define dword size flb_log_event_size_t to prevent invalid casting as a workaround. + */ +#define flb_log_event_size_t uint32_t +#else +#define flb_log_event_size_t size_t +#endif + int flb_log_event_encoder_append_values_unsafe( struct flb_log_event_encoder *context, int field, @@ -28,36 +37,36 @@ int flb_log_event_encoder_append_values_unsafe( int flb_log_event_encoder_append_binary_length( struct flb_log_event_encoder *context, int target_field, - size_t length); + flb_log_event_size_t length); int flb_log_event_encoder_append_binary_body( struct flb_log_event_encoder *context, int target_field, char *value, - size_t length); + flb_log_event_size_t length); int flb_log_event_encoder_append_ext_length( struct flb_log_event_encoder *context, int target_field, int8_t type, - size_t length); + flb_log_event_size_t length); int flb_log_event_encoder_append_ext_body( struct flb_log_event_encoder *context, int target_field, char *value, - size_t length); + flb_log_event_size_t length); int flb_log_event_encoder_append_string_length( struct flb_log_event_encoder *context, int target_field, - size_t length); + flb_log_event_size_t length); int flb_log_event_encoder_append_string_body( struct flb_log_event_encoder *context, int target_field, char *value, - size_t length); + flb_log_event_size_t length); int flb_log_event_encoder_append_int8( struct flb_log_event_encoder *context, @@ -118,20 +127,20 @@ int flb_log_event_encoder_append_binary( struct flb_log_event_encoder *context, int target_field, char *value, - size_t length); + flb_log_event_size_t length); int flb_log_event_encoder_append_string( struct flb_log_event_encoder *context, int target_field, char *value, - size_t length); + flb_log_event_size_t length); int flb_log_event_encoder_append_ext( struct flb_log_event_encoder *context, int target_field, int8_t type, char *value, - size_t length); + flb_log_event_size_t length); int flb_log_event_encoder_append_cstring( struct flb_log_event_encoder *context, @@ -151,7 +160,7 @@ int flb_log_event_encoder_append_raw_msgpack( struct flb_log_event_encoder *context, int target_field, char *value_buffer, - size_t value_size); + flb_log_event_size_t value_size); int flb_log_event_encoder_append_timestamp( struct flb_log_event_encoder *context, diff --git a/src/flb_log_event_encoder_primitives.c b/src/flb_log_event_encoder_primitives.c index 276b3fda3de..a8b60413b32 100644 --- a/src/flb_log_event_encoder_primitives.c +++ b/src/flb_log_event_encoder_primitives.c @@ -38,7 +38,7 @@ int flb_log_event_encoder_append_value( int increment_entry_count, flb_log_event_type_t value_type, char *value_buffer, - size_t value_length) + flb_log_event_size_t value_length) { int result; struct flb_log_event_encoder_dynamic_field *field; @@ -162,7 +162,7 @@ int flb_log_event_encoder_append_value( int flb_log_event_encoder_append_binary_length( struct flb_log_event_encoder *context, int target_field, - size_t length) + flb_log_event_size_t length) { return flb_log_event_encoder_append_value( context, target_field, FLB_TRUE, @@ -174,7 +174,7 @@ int flb_log_event_encoder_append_binary_body( struct flb_log_event_encoder *context, int target_field, char *value, - size_t length) + flb_log_event_size_t length) { return flb_log_event_encoder_append_value( context, target_field, FLB_FALSE, @@ -186,7 +186,7 @@ int flb_log_event_encoder_append_ext_length( struct flb_log_event_encoder *context, int target_field, int8_t type, - size_t length) + flb_log_event_size_t length) { return flb_log_event_encoder_append_value( context, target_field, FLB_TRUE, @@ -198,7 +198,7 @@ int flb_log_event_encoder_append_ext_body( struct flb_log_event_encoder *context, int target_field, char *value, - size_t length) + flb_log_event_size_t length) { return flb_log_event_encoder_append_value( context, target_field, FLB_FALSE, @@ -209,7 +209,7 @@ int flb_log_event_encoder_append_ext_body( int flb_log_event_encoder_append_string_length( struct flb_log_event_encoder *context, int target_field, - size_t length) + flb_log_event_size_t length) { return flb_log_event_encoder_append_value( context, target_field, FLB_TRUE, @@ -221,7 +221,7 @@ int flb_log_event_encoder_append_string_body( struct flb_log_event_encoder *context, int target_field, char *value, - size_t length) + flb_log_event_size_t length) { return flb_log_event_encoder_append_value( context, target_field, FLB_FALSE, @@ -363,7 +363,7 @@ int flb_log_event_encoder_append_binary( struct flb_log_event_encoder *context, int target_field, char *value, - size_t length) + flb_log_event_size_t length) { int result; @@ -387,7 +387,7 @@ int flb_log_event_encoder_append_string( struct flb_log_event_encoder *context, int target_field, char *value, - size_t length) + flb_log_event_size_t length) { int result; @@ -412,7 +412,7 @@ int flb_log_event_encoder_append_ext( int target_field, int8_t type, char *value, - size_t length) + flb_log_event_size_t length) { int result; @@ -461,7 +461,7 @@ int flb_log_event_encoder_append_raw_msgpack( struct flb_log_event_encoder *context, int target_field, char *value_buffer, - size_t value_size) + flb_log_event_size_t value_size) { const flb_log_event_type_t value_type = FLB_LOG_EVENT_MSGPACK_RAW_VALUE_TYPE; @@ -572,7 +572,7 @@ int flb_log_event_encoder_append_values_unsafe( else if (value_type == FLB_LOG_EVENT_STRING_LENGTH_VALUE_TYPE) { result = flb_log_event_encoder_append_string_length(context, target_field, - va_arg(arguments, size_t)); + va_arg(arguments, flb_log_event_size_t)); } else if (value_type == FLB_LOG_EVENT_STRING_BODY_VALUE_TYPE) { buffer_address = va_arg(arguments, char *); @@ -580,12 +580,12 @@ int flb_log_event_encoder_append_values_unsafe( result = flb_log_event_encoder_append_string_body(context, target_field, buffer_address, - va_arg(arguments, size_t)); + va_arg(arguments, flb_log_event_size_t)); } else if (value_type == FLB_LOG_EVENT_BINARY_LENGTH_VALUE_TYPE) { result = flb_log_event_encoder_append_binary_length(context, target_field, - va_arg(arguments, size_t)); + va_arg(arguments, flb_log_event_size_t)); } else if (value_type == FLB_LOG_EVENT_BINARY_BODY_VALUE_TYPE) { buffer_address = va_arg(arguments, char *); @@ -593,7 +593,7 @@ int flb_log_event_encoder_append_values_unsafe( result = flb_log_event_encoder_append_binary_body(context, target_field, buffer_address, - va_arg(arguments, size_t)); + va_arg(arguments, flb_log_event_size_t)); } else if (value_type == FLB_LOG_EVENT_EXT_LENGTH_VALUE_TYPE) { current_ext_type = (int8_t)va_arg(arguments, int32_t); @@ -601,7 +601,7 @@ int flb_log_event_encoder_append_values_unsafe( result = flb_log_event_encoder_append_ext_length(context, target_field, current_ext_type, - va_arg(arguments, size_t)); + va_arg(arguments, flb_log_event_size_t)); } else if (value_type == FLB_LOG_EVENT_EXT_BODY_VALUE_TYPE) { buffer_address = va_arg(arguments, char *); @@ -609,7 +609,7 @@ int flb_log_event_encoder_append_values_unsafe( result = flb_log_event_encoder_append_ext_body(context, target_field, buffer_address, - va_arg(arguments, size_t)); + va_arg(arguments, flb_log_event_size_t)); } else if (value_type == FLB_LOG_EVENT_NULL_VALUE_TYPE) { result = flb_log_event_encoder_append_null(context, @@ -681,7 +681,7 @@ int flb_log_event_encoder_append_values_unsafe( result = flb_log_event_encoder_append_raw_msgpack(context, target_field, buffer_address, - va_arg(arguments, size_t)); + va_arg(arguments, flb_log_event_size_t)); } else if (value_type == FLB_LOG_EVENT_TIMESTAMP_VALUE_TYPE) { result = flb_log_event_encoder_append_timestamp(context,