Skip to content

Commit

Permalink
Merge pull request collectd#4264 from eero-t/gcc-extra
Browse files Browse the repository at this point in the history
[collectd 6, WIP] Fix more GCC "-Wextra" warnings in collectd core
  • Loading branch information
octo authored Jan 31, 2024
2 parents 61a1e35 + 4842d70 commit 81c1f85
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
21 changes: 10 additions & 11 deletions src/utils/format_stackdriver/format_stackdriver.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static int format_gcm_resource(yajl_gen gen, sd_resource_t *res) /* {{{ */
* }
*/
static int format_typed_value(yajl_gen gen, metric_t const *m,
int64_t start_value) {
counter_t start_value) {
char integer[32];

yajl_gen_map_open(gen);
Expand All @@ -150,8 +150,8 @@ static int format_typed_value(yajl_gen gen, metric_t const *m,
}
case METRIC_TYPE_COUNTER: {
/* Counter resets are handled in format_time_series(). */
assert(m->value.counter >= (uint64_t)start_value);
uint64_t diff = m->value.counter - (uint64_t)start_value;
assert(m->value.counter >= start_value);
uint64_t diff = m->value.counter - start_value;
ssnprintf(integer, sizeof(integer), "%" PRIu64, diff);
break;
}
Expand Down Expand Up @@ -280,7 +280,7 @@ static int format_time_interval(yajl_gen gen, metric_t const *m,
* the first time, or reset (the current value is smaller than the cached
* value), the start time is (re)set to vl->time. */
static int read_cumulative_state(metric_t const *m, cdtime_t *ret_start_time,
int64_t *ret_start_value) {
counter_t *ret_start_value) {
/* TODO(octo): Add back DERIVE here. */
if (m->family->type != METRIC_TYPE_COUNTER) {
return 0;
Expand All @@ -290,17 +290,17 @@ static int read_cumulative_state(metric_t const *m, cdtime_t *ret_start_time,
char const *start_time_key = "stackdriver:start_time";

int status =
uc_meta_data_get_signed_int(m, start_value_key, ret_start_value) ||
uc_meta_data_get_unsigned_int(m, start_value_key, ret_start_value) ||
uc_meta_data_get_unsigned_int(m, start_time_key, ret_start_time);
bool is_reset = *ret_start_value > m->value.counter;
if ((status == 0) && !is_reset) {
return 0;
}

*ret_start_value = (int64_t)m->value.counter;
*ret_start_value = m->value.counter;
*ret_start_time = m->time;

return uc_meta_data_add_signed_int(m, start_value_key, *ret_start_value) ||
return uc_meta_data_add_unsigned_int(m, start_value_key, *ret_start_value) ||
uc_meta_data_add_unsigned_int(m, start_time_key, *ret_start_time);
} /* int read_cumulative_state */

Expand All @@ -316,7 +316,7 @@ static int read_cumulative_state(metric_t const *m, cdtime_t *ret_start_time,
* }
*/
static int format_point(yajl_gen gen, metric_t const *m, cdtime_t start_time,
int64_t start_value) {
counter_t start_value) {
/* {{{ */
yajl_gen_map_open(gen);

Expand Down Expand Up @@ -396,7 +396,7 @@ static int format_time_series(yajl_gen gen, metric_t const *m,
metric_type_t type = m->family->type;

cdtime_t start_time = 0;
int64_t start_value = 0;
counter_t start_value = 0;
int status = read_cumulative_state(m, &start_time, &start_value);
if (status != 0) {
return status;
Expand All @@ -412,8 +412,7 @@ static int format_time_series(yajl_gen gen, metric_t const *m,
}
}
if (type == METRIC_TYPE_COUNTER) {
uint64_t sv = (uint64_t)start_value;
if (m->value.counter < sv) {
if (m->value.counter < start_value) {
return EAGAIN;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/match/match.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ typedef struct cu_match_value_s cu_match_value_t;
* Creates a new `cu_match_t' object which will use the regular expression
* `regex' to match lines, see the `match_apply' method below. If the line
* matches, the callback passed in `callback' will be called along with the
* pointer `user_pointer'.
* `user_data' pointer.
* The string that's passed to the callback depends on the regular expression:
* If the regular expression includes a sub-match, i. e. something like
* "value=([0-9][0-9]*)"
Expand Down
7 changes: 4 additions & 3 deletions src/utils/message_parser/message_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static int start_message_assembly(parser_job_data_t *self) {
++(self->message_idx);

/* Resize messages buffer if needed */
if (self->message_idx >= self->messages_max_len) {
if (self->message_idx >= (int)self->messages_max_len) {
INFO(UTIL_NAME ": Exceeded message buffer size: %zu",
self->messages_max_len);
if (self->resize_message_buffer(self, self->messages_max_len +
Expand Down Expand Up @@ -147,8 +147,9 @@ static void end_message_assembly(parser_job_data_t *self) {
self->message_item_idx = 0;
}

static int message_assembler(const char *row, char *const *matches,
size_t matches_num, void *user_data) {
static int message_assembler(__attribute__((unused)) const char *row,
char *const *matches, size_t matches_num,
void *user_data) {
if (user_data == NULL) {
ERROR(UTIL_NAME ": Invalid user_data pointer");
return -1;
Expand Down
6 changes: 3 additions & 3 deletions src/utils/proc_pids/proc_pids.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ int pids_list_clear(pids_list_t *list) {
int pids_list_contains_pid(pids_list_t *list, const pid_t pid) {
assert(list);

for (int i = 0; i < list->size; i++)
for (size_t i = 0; i < list->size; i++)
if (list->pids[i] == pid)
return 1;

Expand Down Expand Up @@ -330,14 +330,14 @@ int pids_list_diff(proc_pids_t *proc, pids_list_t *added,
return pids_list_add_list(removed, proc->prev);
}

for (int i = 0; i < proc->prev->size; i++)
for (size_t i = 0; i < proc->prev->size; i++)
if (0 == pids_list_contains_pid(proc->curr, proc->prev->pids[i])) {
int add_result = pids_list_add_pid(removed, proc->prev->pids[i]);
if (add_result < 0)
return add_result;
}

for (int i = 0; i < proc->curr->size; i++)
for (size_t i = 0; i < proc->curr->size; i++)
if (0 == pids_list_contains_pid(proc->prev, proc->curr->pids[i])) {
int add_result = pids_list_add_pid(added, proc->curr->pids[i]);
if (add_result < 0)
Expand Down

0 comments on commit 81c1f85

Please sign in to comment.