From 716ad8095cc5e778663572fb19aefb3236c62d2f Mon Sep 17 00:00:00 2001 From: Thiago Padilha Date: Mon, 2 Sep 2024 10:48:09 -0300 Subject: [PATCH] processor_calyptia: remove for loop initial declarations Signed-off-by: Thiago Padilha --- .../calyptia_logs_from_lua.c | 3 +- .../calyptia_metrics_from_lua.c | 30 ++++++++++++------- .../calyptia_metrics_to_lua.c | 3 +- .../calyptia_traces_from_lua.c | 15 ++++++---- plugins/processor_calyptia/lua_to_cfl.c | 3 +- 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/plugins/processor_calyptia/calyptia_logs_from_lua.c b/plugins/processor_calyptia/calyptia_logs_from_lua.c index 165772e226a..6bf4e610b6f 100644 --- a/plugins/processor_calyptia/calyptia_logs_from_lua.c +++ b/plugins/processor_calyptia/calyptia_logs_from_lua.c @@ -6,6 +6,7 @@ int calyptia_logs_from_lua(struct flb_processor_instance *ins, lua_State *L, struct flb_mp_chunk_cobj *chunk_cobj) { + int i; int logs_length, metadata_length, timestamps_length; struct flb_mp_chunk_record *record; @@ -41,7 +42,7 @@ int calyptia_logs_from_lua(struct flb_processor_instance *ins, lua_State *L, return -1; } - for (int i = 1; i <= logs_length; i++) { + for (i = 1; i <= logs_length; i++) { record = flb_mp_chunk_record_create(chunk_cobj); if (!record) { flb_plg_error(ins, "failed to create record"); diff --git a/plugins/processor_calyptia/calyptia_metrics_from_lua.c b/plugins/processor_calyptia/calyptia_metrics_from_lua.c index 059af879637..d2ec29a6687 100644 --- a/plugins/processor_calyptia/calyptia_metrics_from_lua.c +++ b/plugins/processor_calyptia/calyptia_metrics_from_lua.c @@ -21,10 +21,11 @@ struct metrics_header { static void free_labels(char **labels, size_t label_count) { + int i; if (!labels) { return; } - for (int i = 0; i < label_count; i++) { + for (i = 0; i < label_count; i++) { if (labels[i]) { free(labels[i]); } @@ -59,7 +60,8 @@ static void split_fqname(const char *fqname, struct metrics_header *header) static int assign_label(char **keys, size_t key_count, char **values, const char *key, const char *value) { - for (size_t i = 0; i < key_count; i++) { + size_t i; + for (i = 0; i < key_count; i++) { if (!strcmp(keys[i], key)) { values[i] = strdup(value); if (!values[i]) { @@ -124,13 +126,14 @@ static double *lua_to_quantile_values(struct flb_processor_instance *ins, lua_State *L, double *quantile_keys, int count) { + int i; double *quantile_values = calloc(count, sizeof(*quantile_values)); if (!quantile_values) { flb_plg_error(ins, "could not allocate memory for quantile values"); return NULL; } - for (int i = 0; i < count; i++) { + for (i = 0; i < count; i++) { lua_pushnumber(L, quantile_keys[i]); lua_gettable(L, -2); quantile_values[i] = lua_to_double(L, -1); @@ -144,13 +147,14 @@ static uint64_t *lua_to_bucket_values(struct flb_processor_instance *ins, lua_State *L, double *bucket_keys, int count) { + int i; uint64_t *values = calloc(count, sizeof(*values)); if (!values) { flb_plg_error(ins, "could not allocate memory for bucket values"); return NULL; } - for (int i = 0; i < count; i++) { + for (i = 0; i < count; i++) { lua_pushnumber(L, bucket_keys[i]); lua_gettable(L, -2); values[i] = lua_to_uint(L); @@ -163,6 +167,7 @@ static uint64_t *lua_to_bucket_values(struct flb_processor_instance *ins, static double *lua_to_quantiles_buckets(struct flb_processor_instance *ins, lua_State *L, int *count) { + int i; double *keys; *count = 0; if (lua_type(L, -1) != LUA_TTABLE) { @@ -183,7 +188,7 @@ static double *lua_to_quantiles_buckets(struct flb_processor_instance *ins, } lua_pushnil(L); // first key - int i = 0; + i = 0; while (lua_next(L, -2) != 0) { keys[i] = lua_to_double(L, -2); i++; @@ -200,6 +205,7 @@ static double *lua_to_quantile_bucket_keys(struct flb_processor_instance *ins, lua_State *L, const char *kind, int *count) { + int i; int sample_count; double *keys; @@ -214,7 +220,7 @@ static double *lua_to_quantile_bucket_keys(struct flb_processor_instance *ins, int found = 0; /* find the first sample that has quantiles */ - for (int i = 1; i <= sample_count; i++) { + for (i = 1; i <= sample_count; i++) { lua_rawgeti(L, -1, i); lua_getfield(L, -1, kind); if (lua_type(L, -1) == LUA_TTABLE) { @@ -240,7 +246,8 @@ static double *lua_to_quantile_bucket_keys(struct flb_processor_instance *ins, static char **append_label(char **labels, size_t *labels_size, size_t *label_index, const char *label) { - for (size_t i = 0; i < *label_index; i++) { + size_t i; + for (i = 0; i < *label_index; i++) { if (!strcmp(labels[i], label)) { /* don't do anything if the label is already in the array */ return labels; @@ -272,6 +279,7 @@ static char **append_label(char **labels, size_t *labels_size, static char **lua_to_label_keys(struct flb_processor_instance *ins, lua_State *L, int *label_count) { + int i; int sample_count; char **label_keys; size_t label_index; @@ -295,7 +303,7 @@ static char **lua_to_label_keys(struct flb_processor_instance *ins, labels_size = 0; label_index = 0; - for (int i = 1; i <= sample_count; i++) { + for (i = 1; i <= sample_count; i++) { lua_rawgeti(L, -1, i); if (lua_type(L, -1) != LUA_TTABLE) { free_labels(label_keys, label_index); @@ -357,6 +365,8 @@ int calyptia_metrics_from_lua(struct flb_processor_instance *ins, lua_State *L, char **label_vals; int label_count; uint64_t timestamp; + int i; + int j; if (lua_type(L, -1) != LUA_TTABLE) { flb_plg_error(ins, "expected metrics array"); @@ -365,7 +375,7 @@ int calyptia_metrics_from_lua(struct flb_processor_instance *ins, lua_State *L, metric_count = lua_objlen(L, -1); - for (int i = 1; i <= metric_count; i++) { + for (i = 1; i <= metric_count; i++) { lua_rawgeti(L, -1, i); label_keys = lua_to_label_keys(ins, L, &label_count); @@ -465,7 +475,7 @@ int calyptia_metrics_from_lua(struct flb_processor_instance *ins, lua_State *L, return -1; } - for (int j = 1; j <= sample_count; j++) { + for (j = 1; j <= sample_count; j++) { label_vals = NULL; /* get sample */ diff --git a/plugins/processor_calyptia/calyptia_metrics_to_lua.c b/plugins/processor_calyptia/calyptia_metrics_to_lua.c index 557ce623889..dd59c97f307 100644 --- a/plugins/processor_calyptia/calyptia_metrics_to_lua.c +++ b/plugins/processor_calyptia/calyptia_metrics_to_lua.c @@ -81,6 +81,7 @@ static void push_histogram(lua_State *L, struct cmt_map *map, static void push_summary(lua_State *L, struct cmt_map *map, struct cmt_metric *metric) { + int i; struct cmt_summary *summary; struct cmt_opts *opts; @@ -89,7 +90,7 @@ static void push_summary(lua_State *L, struct cmt_map *map, if (metric->sum_quantiles_set) { lua_createtable(L, summary->quantiles_count, 0); - for (int i = 0; i < summary->quantiles_count; i++) { + for (i = 0; i < summary->quantiles_count; i++) { lua_pushnumber(L, summary->quantiles[i]); lua_pushnumber(L, cmt_summary_quantile_get_value(metric, i)); lua_settable(L, -3); diff --git a/plugins/processor_calyptia/calyptia_traces_from_lua.c b/plugins/processor_calyptia/calyptia_traces_from_lua.c index ed028d9e8a9..b80a747229c 100644 --- a/plugins/processor_calyptia/calyptia_traces_from_lua.c +++ b/plugins/processor_calyptia/calyptia_traces_from_lua.c @@ -25,6 +25,7 @@ static void lua_to_links(lua_State *L, struct ctrace_span *span) { struct ctrace_link *link; size_t count; + size_t i; struct ctrace_id *trace_id; if (lua_type(L, -1) != LUA_TTABLE) { @@ -32,7 +33,7 @@ static void lua_to_links(lua_State *L, struct ctrace_span *span) } count = lua_objlen(L, -1); - for (size_t i = 1; i <= count; i++) { + for (i = 1; i <= count; i++) { lua_rawgeti(L, -1, i); lua_getfield(L, -1, "traceId"); @@ -68,6 +69,7 @@ static void lua_to_events(lua_State *L, struct ctrace_span *span) { struct ctrace_span_event *event; size_t count; + size_t i; const char *name; if (lua_type(L, -1) != LUA_TTABLE) { @@ -75,7 +77,7 @@ static void lua_to_events(lua_State *L, struct ctrace_span *span) } count = lua_objlen(L, -1); - for (size_t i = 1; i <= count; i++) { + for (i = 1; i <= count; i++) { lua_rawgeti(L, -1, i); lua_getfield(L, -1, "name"); @@ -154,6 +156,7 @@ static void lua_to_spans(lua_State *L, struct ctrace *ctx, size_t count; struct ctrace_span *span; cfl_sds_t name; + size_t i; struct ctrace_id *parent_span_id; if (lua_type(L, -1) != LUA_TTABLE) { @@ -161,7 +164,7 @@ static void lua_to_spans(lua_State *L, struct ctrace *ctx, } count = lua_objlen(L, -1); - for (size_t i = 1; i <= count; i++) { + for (i = 1; i <= count; i++) { lua_rawgeti(L, -1, i); lua_getfield(L, -1, "name"); @@ -224,6 +227,7 @@ static void lua_to_scope_spans(lua_State *L, struct ctrace *ctx, struct ctrace_resource_span *resource_span) { size_t count; + size_t i; struct ctrace_scope_span *scope_span; if (lua_type(L, -1) != LUA_TTABLE) { @@ -232,7 +236,7 @@ static void lua_to_scope_spans(lua_State *L, struct ctrace *ctx, count = lua_objlen(L, -1); - for (size_t i = 1; i <= count; i++) { + for (i = 1; i <= count; i++) { scope_span = ctr_scope_span_create(resource_span); lua_rawgeti(L, -1, i); @@ -257,6 +261,7 @@ static void lua_to_scope_spans(lua_State *L, struct ctrace *ctx, static void lua_to_resource_spans(lua_State *L, struct ctrace *ctx) { size_t count; + size_t i; struct ctrace_resource_span *resource_span; if (lua_type(L, -1) != LUA_TTABLE) { @@ -265,7 +270,7 @@ static void lua_to_resource_spans(lua_State *L, struct ctrace *ctx) count = lua_objlen(L, -1); - for (size_t i = 1; i <= count; i++) { + for (i = 1; i <= count; i++) { resource_span = ctr_resource_span_create(ctx); lua_rawgeti(L, -1, i); diff --git a/plugins/processor_calyptia/lua_to_cfl.c b/plugins/processor_calyptia/lua_to_cfl.c index 4229508b8e8..d96fd905cac 100644 --- a/plugins/processor_calyptia/lua_to_cfl.c +++ b/plugins/processor_calyptia/lua_to_cfl.c @@ -76,9 +76,10 @@ bool lua_isinteger(lua_State *L, int index) struct cfl_array *lua_array_to_variant(lua_State *L, int array_len) { + int i; struct cfl_array *array = cfl_array_create(array_len); - for (int i = 1; i <= array_len; i++) { + for (i = 1; i <= array_len; i++) { lua_rawgeti(L, -1, i); struct cfl_variant *variant = lua_to_variant(L, -1); cfl_array_append(array, variant);