Skip to content

Commit

Permalink
log_event_encoder: define flb_log_event_size_t
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
nokute78 committed Aug 5, 2023
1 parent 1e760b4 commit ea267be
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 37 deletions.
18 changes: 9 additions & 9 deletions include/fluent-bit/flb_log_event_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down Expand Up @@ -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), \
Expand Down
29 changes: 19 additions & 10 deletions include/fluent-bit/flb_log_event_encoder_primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
36 changes: 18 additions & 18 deletions src/flb_log_event_encoder_primitives.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -572,44 +572,44 @@ 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 *);

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 *);

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);

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 *);

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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ea267be

Please sign in to comment.