]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
mdevents.c: fix -Wpedantic warnings on array initialization 4262/head
authorEero Tamminen <eero.t.tamminen@intel.com>
Tue, 30 Jan 2024 11:07:11 +0000 (13:07 +0200)
committerEero Tamminen <eero.t.tamminen@intel.com>
Tue, 30 Jan 2024 11:07:11 +0000 (13:07 +0200)
"{}" 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 <eero.t.tamminen@intel.com>
src/mdevents.c

index d6b80b35dc534636380836cb6f5fa5b93136c1b7..f96b66e16a4a20a2fba8f9352a68afd07b16f2ce 100644 (file)
@@ -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]);