From 9ac32bb2ce9972ff30e0f9dcf2ed76989cdac4f5 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Thu, 14 Jul 2016 17:43:43 +0200 Subject: [PATCH] Fix compilation warnings with GCC 6.1 The new GCC 6.1 considers that "this" is always different from NULL, the compiler produces a warning, and the code is optimized in this sens. this ? "something" : "somethingelse"; will always return "something", even if this is NULL. This C++ trick was used with the alist alist->size() => if null, it returns 0 alist->empty() => if null, it returns true --- bacula/src/dird/fd_cmds.c | 5 ++++- bacula/src/dird/ua_cmds.c | 6 ++++-- bacula/src/dird/ua_dotcmds.c | 2 +- bacula/src/dird/ua_status.c | 2 +- bacula/src/filed/status.c | 2 +- bacula/src/lib/alist.h | 5 ++--- bacula/src/lib/breg.c | 6 ++++-- bacula/src/lib/bsock.c | 3 --- bacula/src/stored/autochanger.c | 4 ++-- bacula/src/stored/status.c | 2 +- bacula/src/tools/bsmtp.c | 2 +- 11 files changed, 21 insertions(+), 18 deletions(-) diff --git a/bacula/src/dird/fd_cmds.c b/bacula/src/dird/fd_cmds.c index c1ebd57c0f..efb5596dc6 100644 --- a/bacula/src/dird/fd_cmds.c +++ b/bacula/src/dird/fd_cmds.c @@ -672,7 +672,9 @@ int send_runscripts_commands(JCR *jcr) int result; Dmsg0(120, "bdird: sending runscripts to fd\n"); - + if (!jcr->job->RunScripts) { + goto norunscript; + } foreach_alist(cmd, jcr->job->RunScripts) { if (cmd->can_run_at_level(jcr->getJobLevel()) && cmd->target) { ehost = edit_job_codes(jcr, ehost, cmd->target, ""); @@ -719,6 +721,7 @@ int send_runscripts_commands(JCR *jcr) goto bail_out; } } +norunscript: free_pool_memory(msg); free_pool_memory(ehost); return 1; diff --git a/bacula/src/dird/ua_cmds.c b/bacula/src/dird/ua_cmds.c index 5ba1a68cf2..334066e829 100644 --- a/bacula/src/dird/ua_cmds.c +++ b/bacula/src/dird/ua_cmds.c @@ -228,8 +228,10 @@ bool do_a_command(UAContext *ua) return false; } - while (ua->jcr->wstorage->size()) { - ua->jcr->wstorage->remove(0); + if (ua->jcr->wstorage) { + while (ua->jcr->wstorage->size()) { + ua->jcr->wstorage->remove(0); + } } len = strlen(ua->argk[0]); diff --git a/bacula/src/dird/ua_dotcmds.c b/bacula/src/dird/ua_dotcmds.c index eda973a7f3..5fbe13f945 100644 --- a/bacula/src/dird/ua_dotcmds.c +++ b/bacula/src/dird/ua_dotcmds.c @@ -1621,7 +1621,7 @@ static bool defaultscmd(UAContext *ua, const char *cmd) ua->send_msg("sdport=%d", storage->SDport); device = (DEVICE *)storage->device->first(); ua->send_msg("device=%s", device->name()); - if (storage->device->size() > 1) { + if (storage->device && storage->device->size() > 1) { while ((device = (DEVICE *)storage->device->next())) { ua->send_msg(",%s", device->name()); } diff --git a/bacula/src/dird/ua_status.c b/bacula/src/dird/ua_status.c index 395966041d..ccf0b84923 100644 --- a/bacula/src/dird/ua_status.c +++ b/bacula/src/dird/ua_status.c @@ -309,7 +309,7 @@ void list_dir_status_header(UAContext *ua) edit_uint64_with_commas(sm_max_buffers, b5)); /* TODO: use this function once for all daemons */ - if (b_plugin_list->size() > 0) { + if (b_plugin_list && b_plugin_list->size() > 0) { int len; Plugin *plugin; POOL_MEM msg(PM_FNAME); diff --git a/bacula/src/filed/status.c b/bacula/src/filed/status.c index 7980117337..b753b58d6a 100644 --- a/bacula/src/filed/status.c +++ b/bacula/src/filed/status.c @@ -90,7 +90,7 @@ static void list_status_header(STATUS_PKT *sp) edit_uint64(debug_level, b2), get_trace(), (int)DEVELOPER_MODE, edit_uint64_with_commas(me->max_bandwidth_per_job/1024, b1)); sendit(msg.c_str(), len, sp); - if (b_plugin_list->size() > 0) { + if (b_plugin_list && b_plugin_list->size() > 0) { Plugin *plugin; int len; pm_strcpy(msg, " Plugin: "); diff --git a/bacula/src/lib/alist.h b/bacula/src/lib/alist.h index c9b041a026..4d83c49d31 100644 --- a/bacula/src/lib/alist.h +++ b/bacula/src/lib/alist.h @@ -103,8 +103,7 @@ inline void * alist::operator [](int index) const { inline bool alist::empty() const { - /* Check for null pointer */ - return this ? num_items == 0 : true; + return num_items == 0; } /* @@ -143,7 +142,7 @@ inline int alist::size() const * on size to succeed even if nothing put in * alist. */ - return this ? num_items : 0; + return num_items; } /* How much to grow by each time */ diff --git a/bacula/src/lib/breg.c b/bacula/src/lib/breg.c index 8034c2c321..2e1a532e82 100644 --- a/bacula/src/lib/breg.c +++ b/bacula/src/lib/breg.c @@ -69,9 +69,11 @@ void free_bregexp(BREGEXP *self) */ void free_bregexps(alist *bregexps) { - Dmsg0(500, "bregexp: freeing all BREGEXP object\n"); - BREGEXP *elt; + Dmsg0(500, "bregexp: freeing all BREGEXP object\n"); + if (!bregexps) { + return; + } foreach_alist(elt, bregexps) { free_bregexp(elt); } diff --git a/bacula/src/lib/bsock.c b/bacula/src/lib/bsock.c index 5cb5d63da4..1a694cc231 100644 --- a/bacula/src/lib/bsock.c +++ b/bacula/src/lib/bsock.c @@ -916,9 +916,6 @@ int BSOCK::wait_data_intr(int sec, int usec) fd_set fdset; struct timeval tv; - if (this == NULL) { - return -1; - } FD_ZERO(&fdset); FD_SET((unsigned)m_fd, &fdset); tv.tv_sec = sec; diff --git a/bacula/src/stored/autochanger.c b/bacula/src/stored/autochanger.c index 8c86d094ef..e3d8180683 100644 --- a/bacula/src/stored/autochanger.c +++ b/bacula/src/stored/autochanger.c @@ -436,7 +436,7 @@ static bool unload_other_drive(DCR *dcr, int slot) int loaded; int i; - if (!changer) { + if (!changer || !changer->device) { return false; } if (changer->device->size() == 1) { @@ -625,7 +625,7 @@ bool autochanger_cmd(DCR *dcr, BSOCK *dir, const char *cmd) if (strcasecmp(cmd, "drives") == 0) { AUTOCHANGER *changer_res = dcr->device->changer_res; int drives = 1; - if (changer_res) { + if (changer_res && changer_res->device) { drives = changer_res->device->size(); } dir->fsend("drives=%d\n", drives); diff --git a/bacula/src/stored/status.c b/bacula/src/stored/status.c index 9a7c173f4b..cac05c8077 100644 --- a/bacula/src/stored/status.c +++ b/bacula/src/stored/status.c @@ -753,7 +753,7 @@ bool qstatus_cmd(JCR *jcr) static void list_plugins(STATUS_PKT *sp) { POOL_MEM msg(PM_MESSAGE); - if (b_plugin_list->size() > 0) { + if (b_plugin_list && b_plugin_list->size() > 0) { Plugin *plugin; int len; pm_strcpy(msg, " Plugin: "); diff --git a/bacula/src/tools/bsmtp.c b/bacula/src/tools/bsmtp.c index 55148d405e..997708d73d 100644 --- a/bacula/src/tools/bsmtp.c +++ b/bacula/src/tools/bsmtp.c @@ -231,7 +231,7 @@ static void get_date_string(char *buf, int buf_len) my_timezone = tz_offset(now, tm); strftime(buf, buf_len, "%a, %d %b %Y %H:%M:%S", &tm); - snprintf(tzbuf, sizeof(tzbuf), " %+2.2ld%2.2u", -my_timezone / 60, abs(my_timezone) % 60); + snprintf(tzbuf, sizeof(tzbuf), " %+2.2ld%2.2u", -my_timezone / 60, (unsigned int)abs(my_timezone) % 60); strcat(buf, tzbuf); /* add +0100 */ strftime(tzbuf, sizeof(tzbuf), " (%Z)", &tm); strcat(buf, tzbuf); /* add (CEST) */ -- 2.39.2