pacemaker/20-Build-2-.c-restore-GCC-9-Werror-buildability-avoid-N.patch
Jan Pokorný 885ffa47ae
2.0.1-0.2.rc3 - Fix buildability with GCC 9 (PR #1681)
Apply minor crm_mon XML output fix (PR #1678)

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-01-22 13:34:01 +01:00

87 lines
3.5 KiB
Diff

From a2e873635db3dfbb696527372dfaad9f58621f48 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= <jpokorny@redhat.com>
Date: Mon, 21 Jan 2019 20:46:56 +0100
Subject: [PATCH] Build: 2 *.c: restore GCC 9 -Werror buildability: avoid NULL
to '%s' arg
Sadly, pacemaker codebase seems to be possibly heavily spoiled with
this undefined behaviour when possibly passing NULL corresponding to
'%s' format specifier argument, so for the time being, fix just what
new GCC 9 started to spot[*] (due to build-time constant NULLs, which
is an immediate proof) since these occurrences boil down to mere
thinkos. Related to that, would be wise to start rolling out
nonnull annotations to preserve more general sanity in this self
explanatory aspect.
Looking at libqb code (end destination of "crm_log" processing), there's
nothing to implicitly mask NULL with a predestined string explicitly
(like glibc make do with "(null)" in majority of the cases), so unless
merely a blackbox is used for logging (qb_vsnprintf_serialize seems to
deal with such a NULL gracefully), passing NULLs where a character array
is expected is rather dangerous without the prior knowledge of
particular libc (vsnprintf) implementation.
[*] https://gcc.gnu.org/git/?p=gcc.git;a=blobdiff;f=gcc/gimple-ssa-sprintf.c;h=456a7d400115713a6600b1ce7bb303b6c971550e;hb=7b2ced2fa2c0597ba083461864c9026c3c9d3720;hpb=b07bf3b9730bebfc9953ea2eeee86a1274e39022
---
daemons/based/based_callbacks.c | 6 +++---
tools/test.iso8601.c | 11 ++++-------
2 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/daemons/based/based_callbacks.c b/daemons/based/based_callbacks.c
index 723e74c876..daef8c7a63 100644
--- a/daemons/based/based_callbacks.c
+++ b/daemons/based/based_callbacks.c
@@ -594,8 +594,8 @@ parse_peer_options_v1(int call_type, xmlNode * request,
return TRUE;
}
- crm_trace("Processing %s request sent by %s", op, originator);
op = crm_element_value(request, F_CIB_OPERATION);
+ crm_trace("Processing %s request sent by %s", op, originator);
if (safe_str_eq(op, "cib_shutdown_req")) {
/* Always process these */
*local_notify = FALSE;
@@ -650,11 +650,11 @@ parse_peer_options_v1(int call_type, xmlNode * request,
} else if (safe_str_eq(op, "cib_shutdown_req")) {
if (reply_to != NULL) {
- crm_debug("Processing %s from %s", op, host);
+ crm_debug("Processing %s from %s", op, originator);
*needs_reply = FALSE;
} else {
- crm_debug("Processing %s reply from %s", op, host);
+ crm_debug("Processing %s reply from %s", op, originator);
}
return TRUE;
diff --git a/tools/test.iso8601.c b/tools/test.iso8601.c
index 6d70af5a4c..93ca4814f6 100644
--- a/tools/test.iso8601.c
+++ b/tools/test.iso8601.c
@@ -8,6 +8,7 @@
#include <crm_internal.h>
#include <crm/crm.h>
#include <crm/common/iso8601.h>
+#include <crm/common/util.h> /* CRM_ASSERT */
#include <unistd.h>
char command = 0;
@@ -46,13 +47,9 @@ static struct crm_option long_options[] = {
static void
log_time_period(int log_level, crm_time_period_t * dtp, int flags)
{
- char *end = NULL;
- char *start = NULL;
-
- if(dtp) {
- start = crm_time_as_string(dtp->start, flags);
- end = crm_time_as_string(dtp->end, flags);
- }
+ char *start = crm_time_as_string(dtp->start, flags);
+ char *end = crm_time_as_string(dtp->end, flags);
+ CRM_ASSERT(start != NULL && end != NULL);
if (log_level < LOG_CRIT) {
printf("Period: %s to %s\n", start, end);