File pacemaker-crm_snprintf_offset-like-parts.patch of Package pacemaker.14737
commit 06e7d9b35b4b93d093083d5f987a0dcd2e48dcff
Author: Jan Pokorný <jpokorny@redhat.com>
Date: Tue Sep 22 15:18:11 2015 +0200
Refactor: crm_snprintf_offset like parts: fix off-by-ones
(On the save side = excessive use, though)
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Index: pacemaker-1.1.16+20170320.77ea74d/lib/common/iso8601.c
===================================================================
--- pacemaker-1.1.16+20170320.77ea74d.orig/lib/common/iso8601.c
+++ pacemaker-1.1.16+20170320.77ea74d/lib/common/iso8601.c
@@ -428,7 +428,7 @@ crm_time_as_string(crm_time_t * date_tim
uint h = 0, m = 0, s = 0;
int offset = 0, max = 128;
- date_s = calloc(1, max+1);
+ date_s = calloc(1, max);
crm_time_get_sec(dt->seconds, &h, &m, &s);
if (date_s == NULL) {
@@ -468,13 +468,13 @@ crm_time_as_string(crm_time_t * date_tim
} else if (flags & crm_time_seconds) {
unsigned long long s = crm_time_get_seconds(date_time);
- snprintf(date_s, 31, "%lld", s); /* Durations may not be +ve */
+ snprintf(date_s, 32, "%lld", s); /* Durations may not be +ve */
goto done;
} else if (flags & crm_time_epoch) {
unsigned long long s = crm_time_get_seconds_since_epoch(date_time);
- snprintf(date_s, 31, "%lld", s); /* Durations may not be +ve */
+ snprintf(date_s, 32, "%lld", s); /* Durations may not be +ve */
goto done;
} else if (flags & crm_time_weeks) {
@@ -482,7 +482,7 @@ crm_time_as_string(crm_time_t * date_tim
uint y, w, d;
if (crm_time_get_isoweek(dt, &y, &w, &d)) {
- snprintf(date_s, 31, "%d-W%.2d-%d", y, w, d);
+ snprintf(date_s, 32, "%d-W%.2d-%d", y, w, d);
}
} else if (flags & crm_time_ordinal) {
@@ -490,7 +490,7 @@ crm_time_as_string(crm_time_t * date_tim
uint y, d;
if (crm_time_get_ordinal(dt, &y, &d)) {
- snprintf(date_s, 31, "%d-%.3d", y, d);
+ snprintf(date_s, 32, "%d-%.3d", y, d);
}
} else {
@@ -498,7 +498,7 @@ crm_time_as_string(crm_time_t * date_tim
uint y, m, d;
if (crm_time_get_gregorian(dt, &y, &m, &d)) {
- snprintf(date_s, 31, "%.4d-%.2d-%.2d", y, m, d);
+ snprintf(date_s, 32, "%.4d-%.2d-%.2d", y, m, d);
}
}
}
@@ -512,7 +512,7 @@ crm_time_as_string(crm_time_t * date_tim
}
if (crm_time_get_timeofday(dt, &h, &m, &s)) {
- snprintf(time_s, 31, "%.2d:%.2d:%.2d", h, m, s);
+ snprintf(time_s, 32, "%.2d:%.2d:%.2d", h, m, s);
}
if (dt->offset != 0) {
@@ -522,10 +522,10 @@ crm_time_as_string(crm_time_t * date_tim
offset_s = calloc(1, 32);
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, 31, "Z");
+ snprintf(offset_s, 32, "Z");
} else {
- snprintf(offset_s, 31, " %c%.2d:%.2d", dt->offset < 0 ? '-' : '+', h, m);
+ snprintf(offset_s, 32, " %c%.2d:%.2d", dt->offset < 0 ? '-' : '+', h, m);
}
}
Index: pacemaker-1.1.16+20170320.77ea74d/lib/common/xml.c
===================================================================
--- pacemaker-1.1.16+20170320.77ea74d.orig/lib/common/xml.c
+++ pacemaker-1.1.16+20170320.77ea74d/lib/common/xml.c
@@ -131,7 +131,7 @@ static inline bool TRACKING_CHANGES(xmlN
} else if(rc >= ((max) - (offset))) { \
char *tmp = NULL; \
(max) = QB_MAX(CHUNK_SIZE, (max) * 2); \
- tmp = realloc_safe((buffer), (max) + 1); \
+ tmp = realloc_safe((buffer), (max)); \
CRM_ASSERT(tmp); \
(buffer) = tmp; \
} else { \
@@ -148,7 +148,7 @@ insert_prefix(int options, char **buffer
if ((*buffer) == NULL || spaces >= ((*max) - (*offset))) {
(*max) = QB_MAX(CHUNK_SIZE, (*max) * 2);
- (*buffer) = realloc_safe((*buffer), (*max) + 1);
+ (*buffer) = realloc_safe((*buffer), (*max));
}
memset((*buffer) + (*offset), ' ', spaces);
(*offset) += spaces;