From 6c71b38164921e50517034d76000da3be3a3f3f8 Mon Sep 17 00:00:00 2001 From: Takahiro Yamashita Date: Sun, 23 Jul 2023 10:47:07 +0900 Subject: [PATCH] log_event_encoder: do not use 'int' type for va_list Signed-off-by: Takahiro Yamashita --- include/fluent-bit/flb_log_event_encoder.h | 72 ++++++++++--------- .../flb_log_event_encoder_primitives.h | 2 +- src/flb_log_event_encoder_primitives.c | 22 +++--- tests/internal/log_event_encoder.c | 12 ++-- 4 files changed, 55 insertions(+), 53 deletions(-) diff --git a/include/fluent-bit/flb_log_event_encoder.h b/include/fluent-bit/flb_log_event_encoder.h index e55cc154349..d4c6c2520ad 100644 --- a/include/fluent-bit/flb_log_event_encoder.h +++ b/include/fluent-bit/flb_log_event_encoder.h @@ -25,7 +25,7 @@ #include #include #include - +#include #include #define FLB_EVENT_ENCODER_SUCCESS 0 @@ -75,112 +75,114 @@ #define FLB_LOG_EVENT_APPEND_UNTIL_TERMINATOR -1 +#define flb_log_event_type_t int32_t + #define FLB_LOG_EVENT_VALUE_LIST_TERMINATOR() \ - (int) FLB_LOG_EVENT_APPEND_TERMINATOR_VALUE_TYPE + (flb_log_event_type_t) FLB_LOG_EVENT_APPEND_TERMINATOR_VALUE_TYPE #define FLB_LOG_EVENT_STRING_LENGTH_VALUE(length) \ - (int) FLB_LOG_EVENT_STRING_LENGTH_VALUE_TYPE, \ + (flb_log_event_type_t) FLB_LOG_EVENT_STRING_LENGTH_VALUE_TYPE, \ (size_t) length #define FLB_LOG_EVENT_STRING_BODY_VALUE(buffer, length) \ - (int) FLB_LOG_EVENT_STRING_BODY_VALUE_TYPE, \ + (flb_log_event_type_t) FLB_LOG_EVENT_STRING_BODY_VALUE_TYPE, \ (char *) buffer, \ (size_t) length #define FLB_LOG_EVENT_BINARY_LENGTH_VALUE(length) \ - (int) FLB_LOG_EVENT_BINARY_LENGTH_VALUE_TYPE, \ + (flb_log_event_type_t) FLB_LOG_EVENT_BINARY_LENGTH_VALUE_TYPE, \ (size_t) length #define FLB_LOG_EVENT_BINARY_BODY_VALUE(buffer, length) \ - (int) FLB_LOG_EVENT_BINARY_BODY_VALUE_TYPE, \ + (flb_log_event_type_t) FLB_LOG_EVENT_BINARY_BODY_VALUE_TYPE, \ (char *) buffer, \ (size_t) length #define FLB_LOG_EVENT_EXT_LENGTH_VALUE(type_, length) \ - (int) FLB_LOG_EVENT_EXT_LENGTH_VALUE_TYPE, \ - (int) type_, \ + (flb_log_event_type_t) FLB_LOG_EVENT_EXT_LENGTH_VALUE_TYPE, \ + (int8_t) type_, \ (size_t) length #define FLB_LOG_EVENT_EXT_BODY_VALUE(buffer, length) \ - (int) FLB_LOG_EVENT_EXT_BODY_VALUE_TYPE, \ + (flb_log_event_type_t) FLB_LOG_EVENT_EXT_BODY_VALUE_TYPE, \ (char *) buffer, \ (size_t) length #define FLB_LOG_EVENT_TIMESTAMP_VALUE(value) \ - (int) FLB_LOG_EVENT_TIMESTAMP_VALUE_TYPE, \ + (flb_log_event_type_t) FLB_LOG_EVENT_TIMESTAMP_VALUE_TYPE, \ (char *) value #define FLB_LOG_EVENT_LEGACY_TIMESTAMP_VALUE(value) \ - (int) FLB_LOG_EVENT_LEGACY_TIMESTAMP_VALUE_TYPE, \ + (flb_log_event_type_t) FLB_LOG_EVENT_LEGACY_TIMESTAMP_VALUE_TYPE, \ (char *) value #define FLB_LOG_EVENT_FORWARD_V1_TIMESTAMP_VALUE(value) \ - (int) FLB_LOG_EVENT_FORWARD_V1_TIMESTAMP_VALUE_TYPE, \ + (flb_log_event_type_t) FLB_LOG_EVENT_FORWARD_V1_TIMESTAMP_VALUE_TYPE, \ (char *) value #define FLB_LOG_EVENT_FLUENT_BIT_V1_TIMESTAMP_VALUE(value) \ - (int) FLB_LOG_EVENT_FLUENT_BIT_V1_TIMESTAMP_VALUE_TYPE, \ + (flb_log_event_type_t) FLB_LOG_EVENT_FLUENT_BIT_V1_TIMESTAMP_VALUE_TYPE, \ (char *) value #define FLB_LOG_EVENT_NULL_VALUE() \ - (int) FLB_LOG_EVENT_NULL_VALUE_TYPE + (flb_log_event_type_t) FLB_LOG_EVENT_NULL_VALUE_TYPE #define FLB_LOG_EVENT_CHAR_VALUE(value) \ - (int) FLB_LOG_EVENT_CHAR_VALUE_TYPE, \ - (int) value + (flb_log_event_type_t) FLB_LOG_EVENT_CHAR_VALUE_TYPE, \ + (int32_t) value #define FLB_LOG_EVENT_INT8_VALUE(value) \ - (int) FLB_LOG_EVENT_INT8_VALUE_TYPE, \ - (int) value + (flb_log_event_type_t) FLB_LOG_EVENT_INT8_VALUE_TYPE, \ + (int32_t) value #define FLB_LOG_EVENT_INT16_VALUE(value) \ - (int) FLB_LOG_EVENT_INT16_VALUE_TYPE, \ - (int) value + (flb_log_event_type_t) FLB_LOG_EVENT_INT16_VALUE_TYPE, \ + (int32_t) value #define FLB_LOG_EVENT_INT32_VALUE(value) \ - (int) FLB_LOG_EVENT_INT32_VALUE_TYPE, \ + (flb_log_event_type_t) FLB_LOG_EVENT_INT32_VALUE_TYPE, \ (int32_t) value #define FLB_LOG_EVENT_INT64_VALUE(value) \ - (int) FLB_LOG_EVENT_INT64_VALUE_TYPE, \ + (flb_log_event_type_t) FLB_LOG_EVENT_INT64_VALUE_TYPE, \ (int64_t) value #define FLB_LOG_EVENT_UINT8_VALUE(value) \ - (int) FLB_LOG_EVENT_UINT8_VALUE_TYPE, \ - (unsigned int) value + (flb_log_event_type_t) FLB_LOG_EVENT_UINT8_VALUE_TYPE, \ + (uint32_t) value #define FLB_LOG_EVENT_UINT16_VALUE(value) \ - (int) FLB_LOG_EVENT_UINT16_VALUE_TYPE, \ - (unsigned int) value + (flb_log_event_type_t) FLB_LOG_EVENT_UINT16_VALUE_TYPE, \ + (uint32_t) value #define FLB_LOG_EVENT_UINT32_VALUE(value) \ - (int) FLB_LOG_EVENT_UINT32_VALUE_TYPE, \ + (flb_log_event_type_t) FLB_LOG_EVENT_UINT32_VALUE_TYPE, \ (uint32_t) value #define FLB_LOG_EVENT_UINT64_VALUE(value) \ - (int) FLB_LOG_EVENT_UINT64_VALUE_TYPE, \ + (flb_log_event_type_t) FLB_LOG_EVENT_UINT64_VALUE_TYPE, \ (uint64_t) value #define FLB_LOG_EVENT_DOUBLE_VALUE(value) \ - (int) FLB_LOG_EVENT_DOUBLE_VALUE_TYPE, \ + (flb_log_event_type_t) FLB_LOG_EVENT_DOUBLE_VALUE_TYPE, \ (double) value #define FLB_LOG_EVENT_BOOLEAN_VALUE(value) \ - (int) FLB_LOG_EVENT_BOOLEAN_VALUE_TYPE, \ - (int) value + (flb_log_event_type_t) FLB_LOG_EVENT_BOOLEAN_VALUE_TYPE, \ + (int32_t) value #define FLB_LOG_EVENT_MSGPACK_OBJECT_VALUE(value) \ - (int) FLB_LOG_EVENT_MSGPACK_OBJECT_VALUE_TYPE, \ + (flb_log_event_type_t) FLB_LOG_EVENT_MSGPACK_OBJECT_VALUE_TYPE, \ (char *) value #define FLB_LOG_EVENT_MSGPACK_RAW_VALUE(buffer, length) \ - (int) FLB_LOG_EVENT_MSGPACK_RAW_VALUE_TYPE, \ + (flb_log_event_type_t) FLB_LOG_EVENT_MSGPACK_RAW_VALUE_TYPE, \ (char *) buffer, \ (size_t) length #define FLB_LOG_EVENT_STRING_VALUE(buffer, length) \ - FLB_LOG_EVENT_STRING_LENGTH_VALUE(length), \ - FLB_LOG_EVENT_STRING_BODY_VALUE(buffer, length) + FLB_LOG_EVENT_STRING_LENGTH_VALUE((size_t)length), \ + FLB_LOG_EVENT_STRING_BODY_VALUE(buffer, (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 1a1400d5806..af6caecdfd2 100644 --- a/include/fluent-bit/flb_log_event_encoder_primitives.h +++ b/include/fluent-bit/flb_log_event_encoder_primitives.h @@ -107,7 +107,7 @@ int flb_log_event_encoder_append_double( int flb_log_event_encoder_append_boolean( struct flb_log_event_encoder *context, int target_field, - int value); + char value); int flb_log_event_encoder_append_character( 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 ca395e3909c..804316d1871 100644 --- a/src/flb_log_event_encoder_primitives.c +++ b/src/flb_log_event_encoder_primitives.c @@ -130,7 +130,7 @@ int flb_log_event_encoder_append_value( *((double *) value_buffer)); } else if (value_type == FLB_LOG_EVENT_BOOLEAN_VALUE_TYPE) { - if (*((int *) value_buffer)) { + if (*((char *) value_buffer)) { result = msgpack_pack_true(&field->packer); } else { @@ -330,7 +330,7 @@ int flb_log_event_encoder_append_double( int flb_log_event_encoder_append_boolean( struct flb_log_event_encoder *context, int target_field, - int value) + char value) { return flb_log_event_encoder_append_value( context, target_field, FLB_TRUE, @@ -554,7 +554,7 @@ int flb_log_event_encoder_append_values_unsafe( int8_t current_ext_type; size_t processed_values; char *buffer_address; - int value_type; + flb_log_event_type_t value_type; int result; processed_values = 0; @@ -564,7 +564,7 @@ int flb_log_event_encoder_append_values_unsafe( processed_values < FLB_EVENT_ENCODER_VALUE_LIMIT && result == FLB_EVENT_ENCODER_SUCCESS ; processed_values++) { - value_type = va_arg(arguments, int); + value_type = va_arg(arguments, flb_log_event_type_t); if (value_type == FLB_LOG_EVENT_APPEND_TERMINATOR_VALUE_TYPE) { break; @@ -596,7 +596,7 @@ int flb_log_event_encoder_append_values_unsafe( va_arg(arguments, size_t)); } else if (value_type == FLB_LOG_EVENT_EXT_LENGTH_VALUE_TYPE) { - current_ext_type = (int8_t) va_arg(arguments, int); + current_ext_type = (int8_t)va_arg(arguments, int32_t); result = flb_log_event_encoder_append_ext_length(context, target_field, @@ -618,17 +618,17 @@ int flb_log_event_encoder_append_values_unsafe( else if (value_type == FLB_LOG_EVENT_CHAR_VALUE_TYPE) { result = flb_log_event_encoder_append_character(context, target_field, - (char) va_arg(arguments, int)); + (char)va_arg(arguments, int32_t)); } else if (value_type == FLB_LOG_EVENT_INT8_VALUE_TYPE) { result = flb_log_event_encoder_append_int8(context, target_field, - (int8_t) va_arg(arguments, int)); + (int8_t)va_arg(arguments, int32_t)); } else if (value_type == FLB_LOG_EVENT_INT16_VALUE_TYPE) { result = flb_log_event_encoder_append_int16(context, target_field, - (int16_t) va_arg(arguments, int)); + (int16_t)va_arg(arguments, int32_t)); } else if (value_type == FLB_LOG_EVENT_INT32_VALUE_TYPE) { result = flb_log_event_encoder_append_int32(context, @@ -643,12 +643,12 @@ int flb_log_event_encoder_append_values_unsafe( else if (value_type == FLB_LOG_EVENT_UINT8_VALUE_TYPE) { result = flb_log_event_encoder_append_uint8(context, target_field, - (uint8_t) va_arg(arguments, unsigned int)); + (uint8_t)va_arg(arguments, uint32_t)); } else if (value_type == FLB_LOG_EVENT_UINT16_VALUE_TYPE) { result = flb_log_event_encoder_append_uint16(context, target_field, - (uint16_t) va_arg(arguments, unsigned int)); + (uint16_t)va_arg(arguments, uint32_t)); } else if (value_type == FLB_LOG_EVENT_UINT32_VALUE_TYPE) { result = flb_log_event_encoder_append_uint32(context, @@ -668,7 +668,7 @@ int flb_log_event_encoder_append_values_unsafe( else if (value_type == FLB_LOG_EVENT_BOOLEAN_VALUE_TYPE) { result = flb_log_event_encoder_append_boolean(context, target_field, - va_arg(arguments, int)); + (char)va_arg(arguments, int32_t)); } else if (value_type == FLB_LOG_EVENT_MSGPACK_OBJECT_VALUE_TYPE) { result = flb_log_event_encoder_append_msgpack_object(context, diff --git a/tests/internal/log_event_encoder.c b/tests/internal/log_event_encoder.c index 564947f9a74..21c26408c5b 100644 --- a/tests/internal/log_event_encoder.c +++ b/tests/internal/log_event_encoder.c @@ -401,8 +401,8 @@ static void basic_format_fluent_bit_v2() FLB_LOG_EVENT_CSTRING_VALUE("key1"), FLB_LOG_EVENT_CSTRING_VALUE("value1"), - FLB_LOG_EVENT_STRING_VALUE("key2", 4), - FLB_LOG_EVENT_STRING_VALUE("value2", 6)); + FLB_LOG_EVENT_STRING_VALUE("key2", (size_t)4), + FLB_LOG_EVENT_STRING_VALUE("value2", (size_t)6)); if (!TEST_CHECK(ret == FLB_EVENT_ENCODER_SUCCESS)) { TEST_MSG("flb_log_event_encoder_append_body_values failed. ret=%s", @@ -465,8 +465,8 @@ static void basic_format_fluent_bit_v1() FLB_LOG_EVENT_CSTRING_VALUE("key1"), FLB_LOG_EVENT_CSTRING_VALUE("value1"), - FLB_LOG_EVENT_STRING_VALUE("key2", 4), - FLB_LOG_EVENT_STRING_VALUE("value2", 6)); + FLB_LOG_EVENT_STRING_VALUE("key2", (size_t)4), + FLB_LOG_EVENT_STRING_VALUE("value2", (size_t)6)); if (!TEST_CHECK(ret == FLB_EVENT_ENCODER_SUCCESS)) { TEST_MSG("flb_log_event_encoder_append_body_values failed. ret=%s", @@ -535,8 +535,8 @@ static void basic_metadata_format_fluent_bit_v2() FLB_LOG_EVENT_CSTRING_VALUE("key1"), FLB_LOG_EVENT_CSTRING_VALUE("value1"), - FLB_LOG_EVENT_STRING_VALUE("key2", 4), - FLB_LOG_EVENT_STRING_VALUE("value2", 6)); + FLB_LOG_EVENT_STRING_VALUE("key2", (size_t)4), + FLB_LOG_EVENT_STRING_VALUE("value2", (size_t)6)); if (!TEST_CHECK(ret == FLB_EVENT_ENCODER_SUCCESS)) { TEST_MSG("flb_log_event_encoder_append_body_values failed. ret=%s",