File pacemaker-prevent-format-truncation.patch of Package pacemaker.14737

commit b4ec771ee4130f283690fec9863fe871f42e395d
Author: Jan Pokorný <jpokorny@redhat.com>
Date:   Wed Feb 15 13:08:07 2017 +0100

    Fix: -Wformat-truncation=2: prevent format truncation
    
    Discovered thanks to -Wformat-truncation=2 of GCC7.
    
    Actually, some instances could gain more conservative upper bound on
    output size.

diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c
index 7f59d737f..c95fa1350 100644
--- a/lib/common/iso8601.c
+++ b/lib/common/iso8601.c
@@ -463,7 +463,7 @@ crm_time_as_string(crm_time_t * date_time, int flags)
     }
 
     if (flags & crm_time_log_date) {
-        date_s = calloc(1, 32);
+        date_s = calloc(1, 34);
         if (date_s == NULL) {
             goto done;
 
@@ -484,7 +484,7 @@ crm_time_as_string(crm_time_t * date_time, int flags)
             uint y, w, d;
 
             if (crm_time_get_isoweek(dt, &y, &w, &d)) {
-                snprintf(date_s, 32, "%u-W%.2u-%u", y, w, d);
+                snprintf(date_s, 34, "%u-W%.2u-%u", y, w, d);
             }
 
         } else if (flags & crm_time_ordinal) {
@@ -492,7 +492,7 @@ crm_time_as_string(crm_time_t * date_time, int flags)
             uint y, d;
 
             if (crm_time_get_ordinal(dt, &y, &d)) {
-                snprintf(date_s, 32, "%u-%.3u", y, d);
+                snprintf(date_s, 22, "%u-%.3u", y, d);
             }
 
         } else {
@@ -500,7 +500,7 @@ crm_time_as_string(crm_time_t * date_time, int flags)
             uint y, m, d;
 
             if (crm_time_get_gregorian(dt, &y, &m, &d)) {
-                snprintf(date_s, 32, "%.4u-%.2u-%.2u", y, m, d);
+                snprintf(date_s, 33, "%.4u-%.2u-%.2u", y, m, d);
             }
         }
     }
@@ -508,26 +508,26 @@ crm_time_as_string(crm_time_t * date_time, int flags)
     if (flags & crm_time_log_timeofday) {
         uint h, m, s;
 
-        time_s = calloc(1, 32);
+        time_s = calloc(1, 33);
         if (time_s == NULL) {
             goto cleanup;
         }
 
         if (crm_time_get_timeofday(dt, &h, &m, &s)) {
-            snprintf(time_s, 32, "%.2u:%.2u:%.2u", h, m, s);
+            snprintf(time_s, 33, "%.2u:%.2u:%.2u", h, m, s);
         }
 
         if (dt->offset != 0) {
             crm_time_get_sec(dt->offset, &h, &m, &s);
         }
 
-        offset_s = calloc(1, 32);
+        offset_s = calloc(1, 31);
         if ((flags & crm_time_log_with_timezone) == 0 || dt->offset == 0) {
             crm_trace("flags %6x %6x", flags, crm_time_log_with_timezone);
-            snprintf(offset_s, 32, "Z");
+            snprintf(offset_s, 31, "Z");
 
         } else {
-            snprintf(offset_s, 32, " %c%.2u:%.2u", dt->offset < 0 ? '-' : '+', h, m);
+            snprintf(offset_s, 24, " %c%.2u:%.2u", dt->offset < 0 ? '-' : '+', h, m);
         }
     }
 
openSUSE Build Service is sponsored by