From a9fd34cd65e01b5320ae3acb474109ca233079fb Mon Sep 17 00:00:00 2001 From: Eero Tamminen Date: Tue, 30 Jan 2024 13:07:11 +0200 Subject: [PATCH] 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 --- src/mdevents.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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]); -- 2.47.2