Skip to content

Commit

Permalink
log_event_encoder: do not use 'int' type for va_list
Browse files Browse the repository at this point in the history
Signed-off-by: Takahiro Yamashita <[email protected]>
  • Loading branch information
nokute78 committed Jul 23, 2023
1 parent 2cdc694 commit 205f2e7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 51 deletions.
68 changes: 35 additions & 33 deletions include/fluent-bit/flb_log_event_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <fluent-bit/flb_mp.h>
#include <fluent-bit/flb_log_event.h>
#include <fluent-bit/flb_log_event_encoder_dynamic_field.h>

#include <inttypes.h>
#include <msgpack.h>

#define FLB_EVENT_ENCODER_SUCCESS 0
Expand Down Expand Up @@ -75,106 +75,108 @@

#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

Expand Down
2 changes: 1 addition & 1 deletion include/fluent-bit/flb_log_event_encoder_primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 11 additions & 11 deletions src/flb_log_event_encoder_primitives.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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));
(uint8_t)va_arg(arguments, uint32_t));
}
else if (value_type == FLB_LOG_EVENT_UINT32_VALUE_TYPE) {
result = flb_log_event_encoder_append_uint32(context,
Expand All @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions tests/internal/log_event_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 205f2e7

Please sign in to comment.