From: Eero Tamminen Date: Tue, 30 Jan 2024 11:07:11 +0000 (+0200) Subject: mdevents.c: fix -Wpedantic warnings on array initialization X-Git-Tag: collectd-6.0.0.rc2~11^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F4262%2Fhead;p=thirdparty%2Fcollectd.git mdevents.c: fix -Wpedantic warnings on array initialization "{}" initializers are C23 feature, not C99 one: https://en.cppreference.com/w/c/language/array_initialization In first 2 cases initialization was redundant as "regerror()" and "regexec()" fill the given arrays. Event initialization needed to be fixed as last struct item writing is conditional. Signed-off-by: Eero Tamminen --- diff --git a/src/mdevents.c b/src/mdevents.c index d6b80b35d..f96b66e16 100644 --- a/src/mdevents.c +++ b/src/mdevents.c @@ -213,9 +213,9 @@ static int md_events_config(const char *key, const char *value) { static void md_events_handle_regex_error(int rc, regex_t *regex, const char *func_name) { - char buf[MAX_ERROR_MSG] = {}; + char buf[MAX_ERROR_MSG]; - regerror(rc, regex, buf, MAX_ERROR_MSG); + regerror(rc, regex, buf, sizeof(buf)); DEBUG("%s() failed with '%s'\n", func_name, buf); } @@ -284,16 +284,17 @@ static void md_events_copy_match(char *buf, const char *line, } static int md_events_match_regex(regex_t *regex, const char *to_match) { - regmatch_t matches[MAX_MATCHES] = {}; + regmatch_t matches[MAX_MATCHES]; int status, severity; - md_events_event_t event = {}; - status = regexec(regex, to_match, MAX_MATCHES, matches, 0); + status = regexec(regex, to_match, STATIC_ARRAY_SIZE(matches), matches, 0); if (status) { md_events_handle_regex_error(status, regex, "regexec"); return -1; } + md_events_event_t event = {0}; + // each element from matches array contains the indexes (start/end) within // the string that we ran regexp on; use them to retrieve the substrings md_events_copy_match(event.event_name, to_match, matches[EVENT]);