File pacemaker#3394-0001-Low-libcrmcommon-Initialize-some-variables.patch of Package pacemaker.38493

From c7a212a91e53a063b2ccf00f457131d8cad7a39e Mon Sep 17 00:00:00 2001
From: Reid Wahl <nrwahl@protonmail.com>
Date: Wed, 20 Mar 2024 17:36:01 -0700
Subject: [PATCH 1/2] Low: libcrmcommon: Initialize some variables

Cppcheck complained about these. There's no point in spending much
effort on iso8601.c until we start the "replace iso8601.c with GLib"
project, but this is easy enough.

Also avoid a variable-length array and fix a harmless off-by-one (we
don't need max + 1 for array size).

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
---
 lib/common/iso8601.c | 38 +++++++++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 11 deletions(-)

Index: pacemaker-2.1.5+20221208.a3f44794f/lib/common/iso8601.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/lib/common/iso8601.c
+++ pacemaker-2.1.5+20221208.a3f44794f/lib/common/iso8601.c
@@ -542,7 +542,9 @@ crm_time_as_string(const crm_time_t *dat
 
     if (flags & crm_time_log_date) {
         if (flags & crm_time_weeks) { // YYYY-WW-D
-            uint32_t y, w, d;
+            uint32_t y = 0;
+            uint32_t w = 0;
+            uint32_t d = 0;
 
             if (crm_time_get_isoweek(dt, &y, &w, &d)) {
                 offset += snprintf(result + offset, DATE_MAX - offset,
@@ -550,7 +552,8 @@ crm_time_as_string(const crm_time_t *dat
             }
 
         } else if (flags & crm_time_ordinal) { // YYYY-DDD
-            uint32_t y, d;
+            uint32_t y = 0;
+            uint32_t d = 0;
 
             if (crm_time_get_ordinal(dt, &y, &d)) {
                 offset += snprintf(result + offset, DATE_MAX - offset,
@@ -558,7 +561,9 @@ crm_time_as_string(const crm_time_t *dat
             }
 
         } else { // YYYY-MM-DD
-            uint32_t y, m, d;
+            uint32_t y = 0;
+            uint32_t m = 0;
+            uint32_t d = 0;
 
             if (crm_time_get_gregorian(dt, &y, &m, &d)) {
                 offset += snprintf(result + offset, DATE_MAX - offset,
@@ -1645,12 +1650,21 @@ pcmk__time_hr_free(pcmk__time_hr_t * hr_
 char *
 pcmk__time_format_hr(const char *format, const pcmk__time_hr_t *hr_dt)
 {
-    const char *mark_s;
-    int max = 128, scanned_pos = 0, printed_pos = 0, fmt_pos = 0,
-        date_len = 0, nano_digits = 0;
-    char nano_s[10], date_s[max+1], nanofmt_s[5] = "%", *tmp_fmt_s;
-    struct tm tm;
-    crm_time_t dt;
+#define DATE_LEN_MAX 128
+    const char *mark_s = NULL;
+    int scanned_pos = 0;
+    int printed_pos = 0;
+    int fmt_pos = 0;
+    size_t date_len = 0;
+    int nano_digits = 0;
+
+    char nano_s[10] = { '\0', };
+    char date_s[DATE_LEN_MAX] = { '\0', };
+    char nanofmt_s[5] = "%";
+    char *tmp_fmt_s = NULL;
+
+    struct tm tm = { 0, };
+    crm_time_t dt = { 0, };
 
     if (!format) {
         return NULL;
@@ -1691,7 +1705,8 @@ pcmk__time_format_hr(const char *format,
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
 #endif
-        date_len += strftime(&date_s[date_len], max-date_len, tmp_fmt_s, &tm);
+        date_len += strftime(&date_s[date_len], DATE_LEN_MAX - date_len,
+                             tmp_fmt_s, &tm);
 #ifdef HAVE_FORMAT_NONLITERAL
 #pragma GCC diagnostic pop
 #endif
@@ -1702,7 +1717,7 @@ pcmk__time_format_hr(const char *format,
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
 #endif
-            date_len += snprintf(&date_s[date_len], max-date_len,
+            date_len += snprintf(&date_s[date_len], DATE_LEN_MAX - date_len,
                                  nanofmt_s, nano_s);
 #ifdef HAVE_FORMAT_NONLITERAL
 #pragma GCC diagnostic pop
@@ -1712,6 +1727,7 @@ pcmk__time_format_hr(const char *format,
     }
 
     return (date_len == 0)?NULL:strdup(date_s);
+#undef DATE_LEN_MAX
 }
 
 /*!
openSUSE Build Service is sponsored by